Use Python to plot the history of local fiscal revenue changes in the past 20 years

The bar_char_race_cn library
solves the problem that the bar_chart_race library does not support Chinese

installation


pip install bar_char_race_cn

Note:
ffmpeg needs to be installed before use

Use
preparation test data


import pandas as pd

df = pd.read_csv('data/财政收入.csv')

def year2timestamp(year):
    #转为可比较大小的日期格式
    return pd.Timestamp(str(year))

df['year'] = df['year'].apply(year2timestamp)
df.set_index('year', inplace=True)
df.sort_index(inplace=True) #日期从小到大排序

Use Python to plot the history of local fiscal revenue changes in the past 20 years

Visualization code

import bar_chart_race_cn as bcr

bcr.bar_chart_race(df=df,
                   filename='近20年各省财政收入.mp4',
                   title='近20年各省财政收入(单位: 亿元)'
                  )

effect

Guess you like

Origin blog.51cto.com/15069487/2578586