python多次绘制条形图
涂兆诚 人气:0运行结果如下
代码如下
from matplotlib import pyplot as plt if __name__ == "__main__": a = ["战狼2","速度与激情8","功夫瑜伽","西游伏妖篇","变形金刚5", "摔跤吧!爸爸","加勒比海盗5","金刚:骷髅岛","极限特工","生化危机6", "乘风破浪","神偷奶爸","智取威虎山","大脑天竺","金刚狼3","蜘蛛侠", "悟空传","银河护卫队2","情圣","新木乃"] b = [56.01,26.94,17.63,16.49,15.45,12.96,11.8,11.61,11.28,11.12,10.49,10.3, 8.75,7.55,7.32,6.99,6.88,6.86,6.58,6.23] #设置图形大小 plt.figure(figsize=(20,8),dpi=80) #绘制条形图 plt.barh(a,b,height=0.3,color="orange") plt.yticks(a,fontproperties='KaiTi') plt.xlabel("票房(单位/亿)",fontproperties='KaiTi',size=25) plt.ylabel("电影名称",fontproperties='KaiTi',size=25) plt.title("电影票房排名情况",fontproperties='KaiTi',size=35) plt.show()
from matplotlib import pyplot as plt from matplotlib import font_manager if __name__ == "__main__": font = font_manager.FontProperties(fname='C:/Windows/fonts/simkai.ttf') a = ["猩球崛起:终极之战","敦刻尔克","蜘蛛侠:英雄归来","战狼2"] b_16 = [15746,312,4997,319] b_15 = [12357,156,2045,168] b_14 = [2358,399,2358,362] bar_width=0.2 #重点,x轴右移 x_14 = list(range(len(a))) x_15 = [i+bar_width for i in x_14] x_16 = [i+bar_width*2 for i in x_14] #设置图形大小像素 plt.figure(figsize=(10,5)) # 绘制条形图 plt.bar(range(len(a)),b_14,width=bar_width,label="9月14日") plt.bar(x_15, b_15, width=bar_width,label="9月15日") plt.bar(x_16, b_16, width=bar_width,label="9月16日") #设置x轴刻度 plt.xticks(x_15,a,fontproperties="KaiTi") #设置图例 plt.legend(prop=font) plt.xlabel("电影名称",fontproperties="KaiTi",size=20) plt.ylabel("票房情况", fontproperties="KaiTi", size=20) plt.title("票房随时间的变化", fontproperties="KaiTi", size=30) plt.show()
加载全部内容