bar chart race in python

bar chart race in python

out.gif 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. image.png 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

Options etc.

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.

Referenced articles

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

bar chart race in python
Progress bar in pop-up in Python Kivy
Write a pie chart in Python
Quadtree in Python --2
Python in optimization
CURL in python
Metaprogramming in Python
Python 3.3 in Anaconda
SendKeys in Python
Epoch in Python
Discord in Python
Sudoku in Python
DCI in Python
quicksort in python
nCr in python
N-Gram in Python
Programming in python
Constant in python
Lifegame in Python.
FizzBuzz in Python
Sqlite in python
StepAIC in Python
N-gram in python
LINE-Bot [0] in Python
Csv in python
Disassemble in Python
Reflection in Python
Constant in python
nCr in Python.
format in python
Scons in Python3
Puyo Puyo in python
python in virtualenv
PPAP in Python
Quad-tree in Python
Reflection in Python
Chemistry in Python
Hashable in python
DirectLiNGAM in Python
LiNGAM in Python
Flatten in python
flatten in python
The one that displays the progress bar in Python
Sorted list in Python
Daily AtCoder # 36 in Python
Clustering text in Python
Daily AtCoder # 2 in Python
Implement Enigma in python
Daily AtCoder # 32 in Python
Daily AtCoder # 6 in Python
Daily AtCoder # 18 in Python
Edit fonts in Python
Singleton pattern in Python
File operations in Python
Read DXF in python
Daily AtCoder # 53 in Python
Key input in Python
Use config.ini in Python
Daily AtCoder # 33 in Python
Solve ABC168D in Python
Logistic distribution in Python