1.1Python绘制柱状图对应代码如下所示
import matplotlib.pyplot as plt import numpy as np from pylab import mpl mpl.rcParams[‘font.sans-serif‘] = [‘STZhongsong‘] # 指定默认字体:解决plot不能显示中文问题 mpl.rcParams[‘axes.unicode_minus‘] = False x=["孙悟空","唐僧","猪八戒","沙悟净"] y=[4,1,3,2] plt.bar(x,y,width=0.5,align="center",label="战力值",color="red") plt.title("师徒战力排行榜",loc="center") for a,b in zip(x,y): plt.text(a,b,b,ha=‘center‘,va="bottom",fontsize=12) plt.xlabel(‘姓名‘) plt.ylabel(‘战力值‘) plt.legend() plt.show()
1.2、最终结果如下图所示