python中利用matplotlib 制作柱状统计比较数据图

import matplotlib.pyplot as plt

import numpy as np

from matplotlib import font_manager

my_font = font_manager.FontProperties(fname=

"C:/Windows/Fonts/msyh.ttc")

a=[u"摔跤吧:爸爸",u"巴霍巴利王2",u"蜘蛛侠:英雄归来",u"金刚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]

#设置图像大小

plt.figure(figsize=(10,10))

ax=plt.subplot(1,1,1)#整体图像的位置

ax.set_title("Counter")#标题居中

ax.set_xlabel("X")

plt.bar(range(len(a)),b_14,width=bar_width,label=u"9月14日")

plt.bar(x_15,b_15,width=bar_width,label=u"9月15日")

plt.bar(x_16,b_16,width=bar_width,label=u"9月16日")

#设置图例

plt.legend(prop=my_font)

#设置x轴的刻度

plt.xticks(x_15,a,fontproperties=my_font)

plt.show()

猜你喜欢

转载自blog.csdn.net/qq_42467563/article/details/82779465
今日推荐