1 回答
TA贡献1784条经验 获得超7个赞
my_xticks1 = ['Montag','Dienstag','Mittwoch','Donnerstag','Freitag' , 'Samstag' , 'Sonntag' , 'aa']
my_major_xticks = ['00' , '00','00','00','00','00' , '00' , '00']
my_minor_xticks = [0 , 5 , 11 , 17 , 23 , 29 , 35 , 41 , 47 , 53 , 59 , 65 , 71 , 77 , 83 , 89 , 95 , 101 , 107 , 113 , 119 , 125 , 131 , 137 , 143 , 149 , 155 , 161 , 167]
my_minor_label = ['06' , '12' , '18' , '06' , '12' , '18' , '06' , '12' , '18' ,'06' , '12' , '18', '06' , '12' , '18' , '06' , '12' , '18' , '06' , '12' , '18']
fig, ax = plt.subplots()
ax.plot(list(dataB.keys()), list(dataB.values()), label="Dec-Feb" , color='#3074bb')
ax.plot(list(dataR.keys()), list(dataR.values()), label="Mar-Apr & Oct-Nov" , color='#bb3530')
ax.plot(list(dataP.keys()), list(dataP.values()), label="Dec-Feb" , color='#a630bb')
ax.plot(list(dataG.keys()), list(dataG.values()), label="Jun-Aug" , color='#30bb40')
ax.set_ylim(ymin=0)
ax.set_xlim(xmin=0)
ax.set_ylabel('Wärmelast / kW')
ax.set_title("Test")
#set the major xticks by its location and the location is presented by the length of the list
plt.xticks([0,23,47,71,95,119,143,167] , my_major_xticks)
# both for x and y axis
ax.tick_params('both', length=7, width=1, which='major')
plt.grid()
# control the minor locator and added a fixedlocator function to it
ax.xaxis.set_minor_locator(FixedLocator(my_minor_xticks))
# add the label to the minor locator
ax.xaxis.set_minor_formatter(FixedFormatter(my_minor_label))
ax.legend()
num = 11
for i, xpos in enumerate(ax.get_xticks()):
if(i == 7):
break;
ax.text(num,-40, my_xticks1[i],
size = 10, ha = 'center')
num = num + 24
我刚刚使用 xticks 、 set_minor_locator 和 ax.text 解决了它 我刚刚发布了上面的代码
添加回答
举报