Creating a Bar Chart Race animation function using
Python
datamahadev.com/creating-a-bar-chart-race-animation-function-using-python
Siddhant Srivastava
Upvote 2+
Bar chart race function in python
Source: Volodymyr from unsplash-datamahadev.com
A bar chart race changes the sequence of bars in an animated way. The data values keep
changing every second in ascending and descending order as shown in the video above.
On 21st February 2019, a tweet by Matt Navarra went viral ann gained approximately 10
million views(1 crore). The tweet showed an animated bar graph that showed the
changing positions of bars of the top 15 brands for the past 19 years. Many a time we
have also seen social media posts related to the bar graph race and it catches the
attention of almost every data enthusiast out there.
All said about bar chart races, have you ever wondered how these animated charts are
made, how are they implemented using Python, if you have then you are at the right
place and this article is definitely for you.
A bar chart race for the number of COVID-19 cases in the states of India starting from
19th April 2020.
Installation
We can install a bar chart race with any of the following ways:
1/4
pip install bar_chart_race
conda install -c conda-forge bar_chart_race
Starting with the code
1) Importing necessary libraries.
2) Reading our dataset.
Output:
3) Convert our original dataset into that form on which we can apply our bar chart race
function. (Here we used pivot table function). Using the data. pivot function to create
data in a pivot table so that it looks more in place to apply the bar chart race.
4) Further data manipulation using sort_values function and dropping a column.
Output:
2/4
The final data frame is prepared for the final function to be applied to the bar chart race
function.
Main function [ bar_chart_race]
There is one main function, bar_chart_race, which will be used to create a bar chart
race.
3/4
Final Output (Bar Chart Race):
A bar chart race output for covid-19 cases in India
Bar chart races using Python is a very good visualization technique to present it in front
of the clients during month-end, quarter-end, or during the annual general meetings of
the companies.
This was our output. We can customize our bar chart race according to our preferences.
Full code can also be found in the link below:
Github Link: https://github.com/Sid-Yo/Covid19_BarChartRace
About me:
My name is Siddhant Srivastava and I am a Data Science
Enthusiast. I have completed IBM Data Science Professional
certification, and I enjoy using my skills to contribute to the
exciting technological advances that happen in the Data Science
field. I am pursuing a Bachelor’s Degree in Electronics and
Communication. I am obsessed with all tech-related things and
I spend my free time exploring new data sets.
Upvote 2+
4/4