條形圖比較

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()

結果:
在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章