比如调查研究生报考人数和录取人数的条形图:
import matplotlib.pyplot as plt
plt.rcParams['font.family']='STSong'
years=['2014','2015','2016','2017','2018','2019']
baokao_nums=[172,164.9,177,201,238,290]
luqu_nums=[54.87,57.06,58.98,72.22,76.25,79.3]
x=range(len(years))
plt.bar(x,height=baokao_nums,width=0.4)
plt.bar([i+0.4 for i in x],luqu_nums,width=0.4)
plt.xticks([i+0.2 for i in x],years)
plt.legend('研究生报考人数','研究生录取人数')
plt.ylabel('人数/万人')
plt.xlabel('年份')
plt.title('研究生历年报考和录取情况')
plt.show()
运行结果如下: