马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
import matplotlib.pyplot as plt
a=["战狼2","速度与激情8","功夫瑜伽","西游伏妖篇","变形金刚5:最后的骑士","摔跤吧!爸爸","加勒比海盗5:死无对证","金刚:骷髅岛","极限特工:终极回归","蝙蝠侠:英雄归来","悟空传","银河护卫队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.bar(a,b, color='lightgreen')
plt.show()
报错:
ValueError: shape mismatch: objects cannot be broadcast to a single shape
我想画一个以a栏为x轴b栏为y轴的柱状图
import matplotlib.pyplot as plt
a=["战狼2","速度与激情8","功夫瑜伽","西游伏妖篇","变形金刚5:\n最后的骑士","摔跤吧!爸爸","加勒比海盗5:\n死无对证",
"金刚:\n骷髅岛","极限特工:\n终极回归","蝙蝠侠:\n英雄归来","悟空传","银河护卫队2","情圣","新木乃伊",'功夫瑜伽',
'烈火英雄','港囧','飞驰人生','侏罗纪世界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.rcParams['font.sans-serif'] = ['SIMHEI']
plt.figure(figsize=(15,5))
plt.bar(range(len(a)),b)
plt.xticks(range(len(a)),a,rotation = -45)
plt.xlabel('电影名')
plt.ylabel('时长(分钟)')
plt.title('20部电影时长统计柱状图')
plt.show()
|