题目
4副图,4中变换,每一次变换都做了一些变化
import matplotlib
import matplotlib.pyplot as plt
matplotlib.rcParams['font.family'] = 'Microsoft YaHei'
a = ["猩球崛起3:终极之战","敦刻尔克","蜘蛛侠:英雄归来","战狼2"]
b_14 = [2358,399,2358,362]
x_14 = [i for i in range(1,14,4)]
b_15 = [12357,156,2045,168]
x_15 = [i+1 for i in x_14]
b_16 = [15746,312,4497,319]
x_16 = [i+1 for i in x_15]
#描绘了数据
fg = plt.figure(figsize=(16,9),dpi=72)
ax1 = fg.add_subplot(221)
ax1.bar(x_14, b_14)
ax1.bar(x_15, b_15)
ax1.bar(x_16, b_16)
#修改x轴的标签
ax2 = fg.add_subplot(222)
ax2.set_xticks(x_15)
ax2.set_xticklabels(a)
ax2.bar(x_14, b_14)
ax2.bar(x_15, b_15)
ax2.bar(x_16, b_16)
#添加了标签
ax3 = fg.add_subplot(223)
ax3.set_xticks(x_15)
ax3.set_xticklabels(a)
ax3.bar(x_14, b_14, label='9月14日')
ax3.bar(x_15, b_15, label='9月15日')
ax3.bar(x_16, b_16, label='9月16日')
ax3.legend(loc='best')
ax3.set_xlabel('电影')
ax3.set_ylabel('票房收入(亿)')
ax3.set_title('三天的票房')
#修改了组距
ax4 = fg.add_subplot(224)
bar_width = 0.2
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]
ax4.set_xticks(x_15)
ax4.set_xticklabels(a)
ax4.bar(x_14, b_14,width=bar_width, label='9月14日')
ax4.bar(x_15, b_15,width=bar_width, label='9月15日')
ax4.bar(x_16, b_16,width=bar_width, label='9月16日')
ax4.legend(loc='best')
ax4.set_xlabel('电影')
ax4.set_ylabel('票房收入(亿)')
ax4.set_title('三天的票房')
plt.show()