import matplotlib.pyplot as plt
from matplotlib import rcParams
from matplotlib.font_manager import FontProperties
rcParams['font.sans-serif']=['SimHei']
rcParams['axes.unicode_minus']=False
font1 = FontProperties(fname=r"c:\windows\fonts\simsun.ttc")
name_list = ['(0,1)', '(0,2)', '(0,3)', '(1,2)', '(1,3)','(1,4)', '(2,3)', '(2,4)', '(3,4)', '(3,5)', '(4,5)', '(3,0)', '(4,0)', '(5,0)']
num_list = [38,171,14,0,22,27,17,0,11,33,80,0,13,42]
num_list120 = [39,23,21,21,45,42,15,13,20,32,5,0,18,63]
num_list80 = [26,17,70,0,94,72,17,0,19,32,617,0,17,99]
x =list(range(len(num_list)))
total_width, n = 1, 4.5
width = total_width / n
plt.figure(figsize=(10,6))
plt.bar(x, num_list, width=width, label='需求不变',fc = 'royalblue')
for i in range(len(x)):
x[i] = x[i] - width
plt.bar(x, num_list120, width=width, label='需求上升',fc='darkblue')
for i in range(len(x)):
x[i] = x[i] + 2*width
plt.bar(x, num_list80, width=width, label='需求下降',fc = 'lightskyblue')
plt.ylabel('XXX',fontproperties=font1, fontsize = 16)
plt.xlabel('XXX' ,fontproperties=font1,fontsize =16)
plt.xticks([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14],name_list,rotation=45, fontsize = 8,fontproperties=font1)
plt.yticks(fontproperties=font1,fontsize = 8)
plt.legend(prop=font1, fontsize = 10)
plt.savefig('XXX',dpi=500, bbox_inches = 'tight')
plt.show()
|