Population Bar Graph
Now let’s make an animated bar graph using the same dataset using population as our primary data in this instance. Let the x of the data be the continent and y be population and when hovered over the names of the countries should be shown. So let’s set hover to ‘country’. It is important to specify range as it helps in understanding the scale of the data we are working on. The parameter on which the animation is done is, of course, the year.
Example:
Python3
import plotly.express as px gapminder = px.data.gapminder() gapminder.head( 15 ) fig = px.bar(gapminder, x = "continent" , y = "pop" , color = 'lifeExp' , animation_frame = 'year' , hover_name = 'country' , range_y = [ 0 , 4000000000 ]) fig.show() |
Output:
Animated Data Visualization using Plotly Express
Data Visualization is a big thing in the data science industry and displaying the proper statistics to a business or governments can help them immeasurably in improving their services. It is very painful to understand data from different times from multiple charts and make any sense of it. That is where the need for animated data visualizations lie. In this, article we are going to use Plotly Express for plotting and animating the data and datasets from Gapminder. We are going to look at different types of animation provided by Plotly Express.