第一步,各种库
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
from matplotlib import animation # 动态柱状图
from IPython.display import HTML
from mpl_toolkits.basemap import Basemap # 构造地图
from matplotlib.patches import Polygon
plt.rcParams['font.sans-serif']=['SimHei']
import warnings
warnings.filterwarnings('ignore')
第二步,动态柱状图
# 交通工具动态图
data = pd.read_csv('tools.csv')
def dynamic_bar(year):
data_2020 = data[data['year']==year].sort_values('number')
ax.clear()
x = data_2020['tool']
x1 = range(9)
y = data_2020['number']
ax.barh(x,y, color='#FD7B0B')
ax.text(500, 3, year, ha='center', va='center', size=30)
plt.ylim((-1,9))
plt.xlim((0,800))
plt.tick_params(labelsize=15)
for i,j in zip(x1, y):
ax.text(j+25, i, str(j/10)+'%', ha='center', va='center', size=