第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何在 matplotlib 中設(shè)置兩個(gè)時(shí)間格式化程序?

如何在 matplotlib 中設(shè)置兩個(gè)時(shí)間格式化程序?

ITMISS 2023-02-07 17:26:51
此圖表由 Excel 構(gòu)建。我怎樣才能使用 matplotlib 做同樣的事情?我的意思是如何添加兩個(gè)格式化程序:年個(gè)月?,F(xiàn)在我使用這樣的東西:現(xiàn)在我使用這樣的東西:fig, ax = plt.subplots(1,1)ax.margins(x=0)ax.plot(list(df['Date']), list(df['Value']), color="g")ax.xaxis.set_major_locator(matplotlib.dates.YearLocator())ax.xaxis.set_major_formatter(matplotlib.dates.DateFormatter('%Y'))plt.text(df["Date"].iloc[-1], df["Value"].iloc[-1], df["Value"].iloc[-1])plt.title(title)plt.get_current_fig_manager().full_screen_toggle()plt.grid(axis = 'y')plt.savefig('pict\\'+sheet.cell_value(row,1).split(',')[0]+'.png', dpi=300, format='png')#plt.show()plt.close(fig)它繪制:
查看完整描述

1 回答

?
慕少森

TA貢獻(xiàn)2019條經(jīng)驗(yàn) 獲得超9個(gè)贊

您應(yīng)該為標(biāo)簽使用輔助軸year,同時(shí)為標(biāo)簽使用主要軸month。您可以使用以下內(nèi)容生成輔助軸:


import matplotlib.pyplot as plt

from mpl_toolkits.axes_grid1 import host_subplot

import mpl_toolkits.axisartist as AA

import matplotlib.dates as md


fig = plt.figure()

months = host_subplot(111, axes_class = AA.Axes, figure = fig)

plt.subplots_adjust(bottom = 0.1)

years = months.twiny()

然后你應(yīng)該將輔助軸移動(dòng)到底部:


offset = -20

new_fixed_axis = years.get_grid_helper().new_fixed_axis

years.axis['bottom'] = new_fixed_axis(loc = 'bottom',

                                      axes = years,

                                      offset = (0, offset))

最后,您繪制然后使用 和 調(diào)整主軸和次軸md.MonthLocator格式md.YearLocator。這樣的事情應(yīng)該沒(méi)問(wèn)題:


months.xaxis.set_major_locator(md.MonthLocator(interval = 1))

months.xaxis.set_major_formatter(md.DateFormatter('%B'))

months.set_xlim([df['Date'].iloc[0], df['Date'].iloc[-1]])


years.xaxis.set_major_locator(md.YearLocator(interval = 1))

years.xaxis.set_major_formatter(md.DateFormatter('%H'))

years.set_xlim([df['Date'].iloc[0], df['Date'].iloc[-1]])


查看完整回答
反對(duì) 回復(fù) 2023-02-07
  • 1 回答
  • 0 關(guān)注
  • 151 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)