Covid-19 - the race we don't want to win
Bar Chart
Bar chart race started to gain popularity recently and some of them went viral. Have you ever wondered how to create one, then this is the time, today we are going to see how we can make use of python to create one on our own with minimal lines of code
Covid-19
If there is one race in the world right now, which none of us want to win then it as to be covid-19. How many of us would have thought about this. Our lives are at stake and my heartfelt condolences for the life that left us in this crucial period. Hope we will find a cure soon until then please be responsible and keep proper social distancing.
So here is how I started to animate the total number of covid-19 affected cases across the world
Libraries used
pandas - to read csv
matplotlib - to plot the graph and to animate
IPython - to display the animation as HTML
Dataset
Read the actual covid-19 affected countries dataset,
Day wise
Plot the dataset on a given day,
Draw Chart
Let's learn to draw a chart, if you see here we have used subplots to draw the chart with the help of figure and an axes, then we used barh to draw horizonal bar chart
Styling
Here comes the aesthytic looks, we can make use of the supported options to alter,
Bar chart race started to gain popularity recently and some of them went viral. Have you ever wondered how to create one, then this is the time, today we are going to see how we can make use of python to create one on our own with minimal lines of code
Covid-19
If there is one race in the world right now, which none of us want to win then it as to be covid-19. How many of us would have thought about this. Our lives are at stake and my heartfelt condolences for the life that left us in this crucial period. Hope we will find a cure soon until then please be responsible and keep proper social distancing.
covid-19 affected countries |
So here is how I started to animate the total number of covid-19 affected cases across the world
Libraries used
pandas - to read csv
matplotlib - to plot the graph and to animate
IPython - to display the animation as HTML
Dataset
Read the actual covid-19 affected countries dataset,
Day wise
Plot the dataset on a given day,
Draw Chart
Let's learn to draw a chart, if you see here we have used subplots to draw the chart with the help of figure and an axes, then we used barh to draw horizonal bar chart
Styling
Here comes the aesthytic looks, we can make use of the supported options to alter,
- Text: Font size, color and placement
- Axis: Labels for x and y axis and its placement
- Credits and Content: Title, content and credits
So we are almost nearing the completion, only animation alone as to be made.
Animation
As we know, Animation/Videos are made up of series of pictures we are using the same logic here with the help of matplotlib.animation module, FuncAnimation is used to animate our barchart with draw_barchart function called continously for the last 130 days,
Also I have used HTML from the IPython module to display our animated barchart as shown below,
Easy right ? then why to wait ? start to explore more and create a bar chart on your own
Inspired by : bar chart race in python
Credits to: pratap vardhan
Good One Ravi!
ReplyDelete