matplotlib学习记录 六

# 绘制多数据条形图

# 假设你知道了列表a中电影分别在2017-09-14(b_14),2017-09-15(b_15),
# 2017-09-16(b_16)三天的票房,为了展示列表中电影本身的票房以及同其他电影的数据对比情况,应该如何更加直观的呈现该数据?

from matplotlib import pyplot as plt

# 让plt能够显示中文
plt.rcParams["font.sans-serif"] = ["SimHei"]

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

x_14 = list(range(len(a)))
x_15 = [i + bar_width for i in x_14]
x_16 = [i + bar_width*2 for i in x_14]

fig = plt.figure(figsize=(10,5),dpi=80)


# 绘图,并设置宽度和图例
plt.bar(x_14,b_14,width=bar_width,label="9月14日")
plt.bar(x_15,b_15,width=bar_width,label="9月15日")
plt.bar(x_16,b_16,width=bar_width,label="9月16日")

# 显示图例
plt.legend()

plt.xticks(x_15,a)

plt.show()

猜你喜欢

转载自www.cnblogs.com/shawone/p/10301493.html