2013-12-09 56 views
0

我有這樣的代碼:如何爲多個子圖創建單個x軸標籤和y軸標籤?

pyplot.figure() 
pyplot.suptitle('Finding the roots of the equation: z^4 - 1 = 0') 
ticks = [-2.0, -1.0, 0.0, 1.0, 2.0] 

pyplot.subplot(221) 
pyplot.imshow(roots, extent=(x0, x1, y0, y1)) 
pyplot.xticks(ticks) 
pyplot.yticks(ticks) 

pyplot.subplot(222) 
pyplot.imshow(iterations, extent=(x0, x1, y0, y1)) 
pyplot.colorbar(orientation='vertical') 
pyplot.xticks(ticks) 
pyplot.yticks(ticks) 

pyplot.subplot(223) 
pyplot.imshow(roots_zoom, extent=(x2, x3, y2, y3)) 

pyplot.subplot(224) 
pyplot.imshow(iterations_zoom, extent=(x2, x3, y2, y3)) 
pyplot.colorbar(orientation='vertical') 

pyplot.show() 

我繪製的數字四組在次要情節的一個2x2的人物形象。我需要爲每個標籤和y標籤。如何創建一個以兩個底圖爲中心的x標籤和一個以左兩個圖爲中心的y標籤?

另外,如何將指定的刻度標記更改爲浮點型?我已經創造了他們爲[-2.0 ... 2.0],但他們圖中所示爲-2,-1,0等

+0

歡迎來到SO!你應該問每個線程一個問題。 – tacaswell

回答

0

可能做到這一點,最簡單的方法是用Figure.text

from matplotlib import pyplot as plt 

fig = plt.gcf() 
fig.text(.5, .1, 'xlabel', ha='center') 
fig.text(.1, .5, 'ylabel', ha='center', rotation='vertical') 

您需要調整文本的位置才能將其正確放置在您想要的位置。

你會想看看Formatter s來控制如何顯示您的刻度線標籤。你可以得到一個小數位浮動與

ax = plt.gca() 
ax.xaxis.set_major_formatter(matplotlib.ticker.FormatStrFormatter('%.1f'))