Recreating Gapminder Animation in 2 lines of Python with Plotly Express

Recreating Gapminder Animation in 2 lines of Python with Plotly ExpressAMRBlockedUnblockFollowFollowingMar 21Disclaimer: A new moduleplotly_express is used, Gapminder Animation not coded from scratch using 2 linesIt’s one of the iconic moments of Data Visualization when Hans Rosling presented the famous Gapminder Animation in his TED talk which is one of the most viewed TED talks ever.

Since then, It’s been like a benchmark for anyone who does visualization to replicate it to show their Data Visualization prowess — much like replicating Edward Tufte’s or Nate Silver’s visualization pieces.

Very recently Plotly (who’s known for their Interactive Visualization DSL for R and Python) came up with a new tool/module/library called Plotly Express.

As the name suggests, the primary objective of plotly express is to be a high-level API that’s insanely simple, fast and easy to use to build Interactive Visualizations.

Much more like this,Plotly Express:Plotly.

py :: Seaborn:MatplotlibInspired by ggplot2 of R and seaborn of Python, having simplicity at its core plotly express attempts to do things in one-liners .

In this piece, We’ll see how to recreate (If not entirely, at least similar to) the iconic Gapminder animation using just plotly express .

Installationpip3 install plotly_expressImport Library with an alias:import plotly_express as pxBubble Chart Animation aka Gapminder Animationpx.



gapminder(), x="gdpPercap", y="lifeExp", animation_frame="year", animation_group="country", size="pop", color="country", hover_name="country", log_x = True, size_max=45, range_x=[100,100000], range_y=[25,90])That’s a pretty simplistic function (I’ve ever seen to do this Gapminder Animation).

The function px.

scatter() gets the data from px.


gapminder() and then typically, defining x and y axis along with the animation_frame that gets incremented for every year.

With a few more arguments for cosmetic improvements, the Animated Bubble Chart is ready!Screencast Video:FINThe objective of this post is to spread out the word about plotly_express which is nothing short of amazing to create beautiful interactive visualization (also similar to highcharter in R).

If you want a course of Plotly in general, Check out Datacamp.

ResourcesComplete Code used in this PostA very comprehensive intro to Plotly ExpressPlotly Documentation.

. More details

Leave a Reply