条形图比较

from matplotlib import pyplot as plt
import matplotlib

font = {'family': 'MicroSoft YaHei',
        'weight': 'bold',
        'size': '7'}
matplotlib.rc("font", **font)

a = ['战狼2', '速度与\n激情8', '功夫瑜伽', '西游降\n妖篇', '变形金\n刚5', '最后的\n骑士']

b = [56.01, 26.94, 17.53, 16.49, 15.54, 12.96]
b1 = [53.01, 34.94, 45.53, 34.49, 55.54, 29.6]
b2 = [54.01, 23.94, 17.53, 56.49, 34.54, 9.566]
# 设置X轴坐标
bar_width = 0.2
# 两个柱状图之间相隔width=7
x_14 = list(range(len(a)))
x_15 = [i + bar_width for i in x_14]
x_16 = [i + bar_width for i in x_15]
plt.figure(figsize=(8, 20), dpi=80)

plt.bar(x_14, b, width=bar_width, color='#cc00cc', label='9月14号')
plt.bar(x_15, b1, width=bar_width, color='#ccff33', label='9月15号')
plt.bar(x_16, b2, width=bar_width, color='#9932CC', label='9月16号')
plt.legend()
plt.xticks(x_15, a, rotation=60)
plt.title('14、15、16三天电影票售卖情况')
plt.xlabel('电影名称')
plt.ylabel('票房(万)')
plt.grid(alpha=0.3, linestyle='--', linewidth=1)
plt.savefig('../Images/bar比较.png')
plt.show()

结果:
在这里插入图片描述

发布了49 篇原创文章 · 获赞 18 · 访问量 1402

猜你喜欢

转载自blog.csdn.net/qq_44099721/article/details/103898745