基本演示
和折现图相似 折线图
使用 plt.bar(range(len(x)), y, width=0.3, color="green")
绘制竖着的条形图
使用plt.barh(range(len(x)), y, height=0.3)
绘制横着的条形图
from matplotlib import pyplot as plt
# 中文
import matplotlib
font = {'family': 'MicroSoft Yahei',
# 'weight': 'bold',
'size': '10'}
matplotlib.rc('font', **font)
x = ["战狼2", "速度与激情8", "功夫瑜伽", "西游伏妖篇", "变形金刚5\n:最后的骑士", "摔跤吧!爸爸", "加勒比海盗5:\n死无对证", "金刚:\n骷髅岛", "极限特工:\n终极回归", "生化危机6:\n终章",
"乘风破浪", "神偷奶爸3", "智取威虎山", "大闹天竺", "金刚狼3:\n殊死一战", "蜘蛛侠:\n英雄归来", "悟空传", "银河护卫队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, 15), dpi=80)
# 绘制条形图
plt.bar(range(len(x)), y, width=0.3, color="green")
plt.xticks(range(len(x)), x, rotation=90)
plt.grid(alpha=0.3)
plt.savefig("./move.png")
plt.show()
同时画多个图
from matplotlib import pyplot as plt
# 中文
import matplotlib
font = {'family': 'MicroSoft Yahei',
'weight': 'bold',
'size': '10'}
matplotlib.rc('font', **font)
a = ["猩球崛起3:终极之战","敦刻尔克","蜘蛛侠:英雄归来","战狼2"]
b_16 = [15746,312,4497,319]
b_15 = [12357,156,2045,168]
b_14 = [2358,399,2358,362]
bar_width = 0.2
a_14 = range(len(a))
a_15 = [i + bar_width for i in a_14]
a_16 = [i + bar_width for i in a_15]
plt.bar(a_14, b_14, width=bar_width, label="14日")
plt.bar(a_15, b_15, width=bar_width, label="15日")
plt.bar(a_16, b_16, width=bar_width, label="16日")
# x轴的刻度
plt.xticks(a_15, a)
# 设置图例
plt.legend()
plt.show()