亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Matplotlib - 以天和小時為單位繪制日期(x 軸)與值(y 軸)

Matplotlib - 以天和小時為單位繪制日期(x 軸)與值(y 軸)

拉風的咖菲貓 2024-01-04 17:24:39
我有一個xlsx包含兩列的文件。第一個是時間戳 (DT-Index),如下所示 (18.01.2012 06:00:00),第二個包含正常值。我有 1 年的時間戳,每天 24 小時,總共 8736 個值?,F在我想繪制這些數據,如下圖所示。我面臨的問題是,有很多天,當我嘗試像這樣繪制它們時,我會出現 20 次甚至更多的星期一。如何實現如圖所示的解決方案?
查看完整描述

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 解決了它 我剛剛發布了上面的代碼


查看完整回答
反對 回復 2024-01-04
  • 1 回答
  • 0 關注
  • 149 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號