pythonmatplotlib库绘制条形图练习题-创新互联
练习一:假设你获取到了2017年内地电影票房前20的电影(列表a)和电影票房数据(列表b),那么如何更加直观的展示该数据?
成都创新互联是一家专注于成都网站设计、成都网站制作与策划设计,苏州网站建设哪家好?成都创新互联做网站,专注于网站建设十年,网设计领域的专业建站公司;建站业务涵盖:苏州等地区。苏州做网站价格咨询:13518219792a = ["战狼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]
from matplotlib import pyplot as plt import matplotlib """绘制条形图""" font = {'family': 'MicroSoft YaHei'} matplotlib.rc('font', **font) # 使支持中文 x = ["战狼2","速度与激情8","功夫瑜伽","西游伏妖篇","变形金刚5:最后的骑士","摔跤吧!爸爸","加勒比海盗5:死无对证","金刚:骷髅岛","极限特工:终极回归","生化危机6:终章","乘风破浪","神偷奶爸3","智取威虎山","大闹天竺","金刚狼3:殊死一战","蜘蛛侠:英雄归来","悟空传","银河护卫队2","情圣","新木乃伊",] 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] plt.figure(figsize=(20, 8), dpi=80) # 设置图形大小 # plt.bar(range(len(x)), y, width=0.3) # 绘制条形图,线条宽度 plt.barh(range(len(x)), y, height=0.3, color='orange') # 绘制横着的条形图,横着的用height控制线条宽度 # 设置字符串到x轴 plt.yticks(range(len(x)),x) plt.grid(alpha=0.3) # 添加网格 plt.ylabel('电影名称') plt.xlabel('票房') plt.title('票房前20的电影') plt.show()
本文标题:pythonmatplotlib库绘制条形图练习题-创新互联
文章URL:http://scyingshan.cn/article/dhhooc.html