這是對this後的一種後續問題,其中討論了軸,蜱和標籤的着色。我希望爲此打開一個新的擴展問題是可以的。在matplotlib中優雅地改變情節框架的顏色
用軸[ax1,ax2]圍繞雙圖(通過add_subplot
)更改完整框架(滴答和軸)的顏色會產生大量代碼。這段代碼改變上面的曲線的框架的顏色:(!)
ax1.spines['bottom'].set_color('green')
ax1.spines['top'].set_color('green')
ax1.spines['left'].set_color('green')
ax1.spines['right'].set_color('green')
for t in ax1.xaxis.get_ticklines(): t.set_color('green')
for t in ax1.yaxis.get_ticklines(): t.set_color('green')
for t in ax2.xaxis.get_ticklines(): t.set_color('green')
for t in ax2.yaxis.get_ticklines(): t.set_color('green')
因此改變兩幅地塊的邊框顏色有兩個Y軸各,我需要16行代碼..這是它的樣子:
其他方法我挖出至今:
matplotlib.rc:討論here;全球變化,而非本地變化。我想要用不同顏色的其他情節。請,不愁太多的顏色在情節的討論... :-)
matplotlib.rc('axes',edgecolor='green')
挖掘出軸的刺,然後改變它:還討論here;我覺得不是很優雅。
for child in ax.get_children(): if isinstance(child, matplotlib.spines.Spine): child.set_color('#dddddd')
有冷凝以上塊的優雅方式,一些 更 「Python化」?
我在ubuntu下使用python 2.6.5和matplotlib 0.99.1.1。
不錯的一個。請包括雙色,我會'接受'你的答案。 (如:斧頭,拉鍊顏色([ax1,ax2,ax3,ax4],['green','green','blue','blue']): plt.setp(ax.spines.values (),color = color); plt.setp([ax.get_xticklines(),ax.get_yticklines()],color = color)') – Boffin
@Boffin done :) – ianalis
在你的最後一行我認爲你的意思是'ax1 '只是'ax' – Joel