a = ["战狼2","速度与激情8","功夫瑜伽","西游伏妖篇","变形金刚5:最后的骑士","摔跤吧!爸爸","加勒比海盗5:死无对证","金刚:骷髅岛","极限特工:终极回归","生化危机6:终章","乘风破浪","神偷奶爸3","智取威虎山","大闹天竺","金刚狼3:殊死一战","蜘蛛侠:英雄归来","悟空传","银河护卫队2","情圣","新木乃伊",]
b = [56.01,26.94,17.53,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]
1 from matplotlib import pyplot as plt 2 import matplotlib 3 4 """绘制条形图""" 5 font = {‘family‘: ‘MicroSoft YaHei‘} 6 matplotlib.rc(‘font‘, **font) # 使支持中文 7 8 x = ["战狼2","速度与激情8","功夫瑜伽","西游伏妖篇","变形金刚5:最后的骑士","摔跤吧!爸爸","加勒比海盗5:死无对证","金刚:骷髅岛","极限特工:终极回归","生化危机6:终章","乘风破浪","神偷奶爸3","智取威虎山","大闹天竺","金刚狼3:殊死一战","蜘蛛侠:英雄归来","悟空传","银河护卫队2","情圣","新木乃伊",] 9 10 y = [56.01,26.94,17.53,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] 11 12 plt.figure(figsize=(20, 8), dpi=80) # 设置图形大小 13 14 # plt.bar(range(len(x)), y, width=0.3) # 绘制条形图,线条宽度 15 plt.barh(range(len(x)), y, height=0.3, color=‘orange‘) # 绘制横着的条形图,横着的用height控制线条宽度 16 # 设置字符串到x轴 17 plt.yticks(range(len(x)),x) 18 19 plt.grid(alpha=0.3) # 添加网格 20 plt.ylabel(‘电影名称‘) 21 plt.xlabel(‘票房‘) 22 plt.title(‘票房前20的电影‘) 23 24 plt.show()
a = ["猩球崛起3:终极之战","敦刻尔克","蜘蛛侠:英雄归来","战狼2"]
b_16 = [15746,312,4497,319]
b_15 = [12357,156,2045,168]
b_14 = [2358,399,2358,362]
1 from matplotlib import pyplot as plt 2 import matplotlib 3 4 font = {‘family‘: ‘MicroSoft YaHei‘} 5 matplotlib.rc(‘font‘, **font) # 使支持中文 6 7 a = ["猩球崛起3:终极之战","敦刻尔克","蜘蛛侠:英雄归来","战狼2"] 8 b_16 = [15746,312,4497,319] 9 b_15 = [12357,156,2045,168] 10 b_14 = [2358,399,2358,362] 11 12 bar_width = 0.2 # 绘制多个条形图,这里不能大于0.3 13 # 让后两个条形,向后移动一个bar_width 14 x_14 = list(range(len(a))) 15 x_15 = [i+bar_width for i in x_14] 16 x_16 = [i+2*bar_width for i in x_14] 17 18 plt.figure(figsize=(20, 8), dpi=80) # 设置图形大小 19 plt.xticks(x_15, a) # 设置x轴刻度 20 21 plt.bar(range(len(a)), b_14, width=bar_width, label=‘9月14日‘) 22 plt.bar(x_15, b_15, width=bar_width, label=‘9月15日‘) 23 plt.bar(x_16, b_16, width=bar_width, label=‘9月16日‘) 24 25 plt.legend() # 设置图例 26 plt.xlabel(‘电影名称‘) 27 plt.ylabel(‘票房/万‘) 28 plt.title(‘对比票房‘) 29 plt.savefig(‘./02.png‘) 30 plt.show()
原文:https://www.cnblogs.com/springionic/p/11150192.html