It seems that bar graph lace that you often see on Youtube etc. is created with flourish, but I will introduce it because there is a library created with python. See below for installation, usage and Dependency. https://www.dexplo.org/bar_chart_race/ It's super easy to use, just store each date record in a pandas DataFrame with each data name in a column and call the function. Specifically, prepare such data. I'm just giving this to the function, but Google has published a forecast for the next 28 days of Covid-19, so I'll use it as sample data. Below is the sample code.
import pandas as pd
import bar_chart_race as bcr
df = pd.read_csv('https://storage.googleapis.com/covid-external/forecast_JAPAN_PREFECTURE_28.csv')
df = df.pivot_table(index='target_prediction_date',
columns='prefecture_name',
values='cumulative_confirmed')
bcr.bar_chart_race(df=df, n_bars=10)
Run it on Jupyter and after a while you should see the animation. What is pivoted on the 4th line is that Google records are records for each Prefecture, so here we focus on the cumulative number of positives (cumulative_confirmed) and place the numbers for each prefecture in the column. .. The converted DataFrame is the above image. Google has announced various other predicted values, so it is a good idea to try different arguments of values. https://storage.googleapis.com/covid-external/COVID-19ForecastUserGuideJapan_Japanese.pdf
n_bars = 10
is an option to display the Top 10, and if omitted, it will be a bar graph. You can create mpeg videos and gif animations with the filename
option, but you need to install ffmpeg and ImageMagick separately. Other options such as vertical graphs and titles are described in great detail on the author's site above, so it's faster to see them.
Convert video to GIF with FFmpeg (to create top compressed GIF image) Two-dimensional random walk + save gif of matplotlib.animation in Python (Install ImageMagick) Create a Bar Chart Race Animation in Python with Matplotlib
Recommended Posts