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

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

matplotlib中的日期刻度和旋轉(zhuǎn)

matplotlib中的日期刻度和旋轉(zhuǎn)

慕桂英3389331 2019-08-31 15:09:36
我有一個(gè)問(wèn)題試圖讓我的日期刻度在matplotlib中旋轉(zhuǎn)。下面是一個(gè)小樣本程序。如果我嘗試在末尾旋轉(zhuǎn)刻度線,則刻度線不會(huì)旋轉(zhuǎn)。如果我嘗試旋轉(zhuǎn)注釋'崩潰'下顯示的刻度,則matplot lib崩潰。只有當(dāng)x值是日期時(shí)才會(huì)發(fā)生這種情況。如果我用調(diào)用中dates的變量替換變量,則調(diào)用在內(nèi)部工作正常。tavail_plotxticks(rotation=70)avail_plot有任何想法嗎?import numpy as npimport matplotlib.pyplot as pltimport datetime as dtdef avail_plot(ax, x, y, label, lcolor):    ax.plot(x,y,'b')    ax.set_ylabel(label, rotation='horizontal', color=lcolor)    ax.get_yaxis().set_ticks([])    #crashes    #plt.xticks(rotation=70)    ax2 = ax.twinx()    ax2.plot(x, [1 for a in y], 'b')    ax2.get_yaxis().set_ticks([])    ax2.set_ylabel('testing')f, axs = plt.subplots(2, sharex=True, sharey=True)t = np.arange(0.01, 5, 1)s1 = np.exp(t)start = dt.datetime.now()dates=[]for val in t:    next_val = start + dt.timedelta(0,val)    dates.append(next_val)    start = next_valavail_plot(axs[0], dates, s1, 'testing', 'green')avail_plot(axs[1], dates, s1, 'testing2', 'red')plt.subplots_adjust(hspace=0, bottom=0.3)plt.yticks([0.5,],("",""))#doesn't crash, but does not rotate the xticks#plt.xticks(rotation=70)plt.show()
查看完整描述

3 回答

?
慕虎7371278

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

如果您更喜歡非面向?qū)ο蟮姆椒?,?qǐng)?jiān)趦纱蝍vail_plot調(diào)用之前將plt.xticks(rotation = 70)移到右側(cè),例如


plt.xticks(rotation=70)

avail_plot(axs[0], dates, s1, 'testing', 'green')

avail_plot(axs[1], dates, s1, 'testing2', 'red')

這會(huì)在設(shè)置標(biāo)簽之前設(shè)置rotation屬性。由于這里有兩個(gè)軸,因此在制作完兩個(gè)圖之后,plt.xticks會(huì)變得混亂。而此時(shí)plt.xticks不會(huì)做任何事情的地步,plt.gca()并沒(méi)有給你作用于當(dāng)前坐標(biāo)要修改的軸,所以plt.xticks,是行不通的。


對(duì)于不使用plt.xticks的面向?qū)ο蠓椒?,您可以使?/p>


plt.setp( axs[1].xaxis.get_majorticklabels(), rotation=70 )

在兩次avail_plot調(diào)用之后。這樣就可以在正確的軸上設(shè)置旋轉(zhuǎn)。


查看完整回答
反對(duì) 回復(fù) 2019-08-31
?
大話西游666

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

解決方案適用于matplotlib 2.1+


存在tick_params可以改變刻度屬性的軸方法。它也作為軸方法存在set_tick_params


ax.tick_params(axis='x', rotation=45)

要么


ax.xaxis.set_tick_params(rotation=45)

作為旁注,當(dāng)前的解決方案通過(guò)使用命令將狀態(tài)接口(使用pyplot)與面向?qū)ο蟮慕涌诨旌蟨lt.xticks(rotation=70)。由于問(wèn)題中的代碼使用面向?qū)ο蟮姆椒?,因此最好始終堅(jiān)持使用該方法。該解決方案確實(shí)提供了一個(gè)很好的顯式解決方plt.setp( axs[1].xaxis.get_majorticklabels(), rotation=70 )


查看完整回答
反對(duì) 回復(fù) 2019-08-31
  • 3 回答
  • 0 關(guān)注
  • 2546 瀏覽
慕課專欄
更多

添加回答

舉報(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)