假设你获取到了2017年内地电影票房前20的电影(列表a)和电影票房数据(列表b),那么如何更加直观的展示该数据?
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] 单位:亿
数据来源: http://58921.com/alltime/2017
from matplotlib import pyplot as plt
plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签
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]
#设置图形大小
plt.figure(figsize=(20,8),dpi=80)
#a字符串转换为数字列表
_x = range(len(a))
_y = b
#绘制竖着的条形图,用width设置条形图粗细
plt.bar(a,_y,color = "cyan",width = 0.1)
#通过设置xticks让数字和字符串对应
plt.xticks(_x,a,rotation = 45)
#设置描述信息
plt.xlabel("电影名称")
plt.ylabel("电影票房")
plt.title("电影票房数据")
#添加水印
plt.text(5,5, '专属标志',
fontsize=100, color='gray',
ha = "left",va ="bottom",alpha=0.1)
# plt.savefig(".\h.png")
plt.show()
from matplotlib import pyplot as plt
plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签
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]
#设置图形大小
plt.figure(figsize=(20,8),dpi=80)
#a字符串转换为数字列表
_x = range(len(a))
_y = b
#绘制横着的条形图,用height设置条形图粗细
plt.barh(a,_y,color = "red",height = 0.1)
#通过设置xticks让数字和字符串对应
plt.yticks(_x,a)
#设置描述信息
plt.xlabel("电影票房 单位:亿")
plt.title("电影票房数据")
plt.grid(alpha =0.3)
#添加水印
plt.text(5,5, '专属标志',
fontsize=100, color='gray',
ha = "left",va ="bottom",alpha=0.1)
# plt.savefig(".\h.png")
plt.show()
假设你知道了列表a中电影分别在2017-09-14(b_14), 2017-09-15(b_15), 2017-09-16(b_16)三天的票房,为了展示列表中电影本身的票房以及同其他电影的数据对比情况,应该如何更加直观的呈现该数据?
a = [“猩球崛起3:终极之战”,“敦刻尔克”,“蜘蛛侠:英雄归来”,“战狼2”]
b_16 = [15746,312,4497,319]
b_15 = [12357,156,2045,168]
b_14 = [2358,399,2358,362]
数据来源: http://www.cbooo.cn/movieday
from matplotlib import pyplot as plt
#用来正常显示中文标签
plt.rcParams['font.sans-serif']=['SimHei']
a = ["猩球崛起3:终极之战","敦刻尔克","蜘蛛侠:英雄归来","战狼2"]
b_16 = [15746,312,4497,319]
b_15 = [12357,156,2045,168]
b_14 = [2358,399,2358,362]
#设置图形大小
plt.figure(figsize=(20,8),dpi=80)
#a字符串转换为数字列表
x_14 = list(range(len(a)))
x_15 = [i+0.2 for i in x_14]
x_16 = [i+0.2 for i in x_15]
#绘制条形图
bar_width = 0.2
plt.bar(x_14,b_14,color = "red",width = bar_width,label = "9月14号")
plt.bar(x_15,b_15,color = "orange",width = bar_width,label ="9月15号")
plt.bar(x_16,b_16,color = "blue",width = bar_width,label ="9月16号")
#通过设置xticks让数字和字符串对应,位于三条条形的中间
plt.xticks(x_15,a)
#设置描述信息
plt.xlabel("电影名称")
plt.title("电影票房数据")
plt.grid(alpha =0.3)
#设置图例
plt.legend()
#添加水印
plt.text(5,5, '专属标志',
fontsize=100, color='gray',
ha = "left",va ="bottom",alpha=0.1)
# plt.savefig(".\h.png")
plt.show()