2014-03-18 190 views
1

假設我有一個有多個座標軸共享座標圖的座標圖,如下圖所示。我如何控制x_ticks在所有子圖共享的x軸上的位置?在座標軸共享圖上設置座標軸屬性

例如,假設我想僅在X的下列值上顯示刻度:0, 50 and 100。據我所知,對於方法ax.set_xticks我需要指定一個軸,但它們都共享一個,我如何得到它的句柄?

f, axes = plt.subplots(3, sharex=True, sharey=True) 
for ix in xrange(3): 
    ax = axes[ix] 
    t = np.arange(0.0, 100.0, 0.1) 
    s = np.sin(0.1*np.pi*t)*np.exp(-t*0.01) 

    ax.plot(t,s) 

更新:

如何我也有我所有的次要情節是垂直居中一個ylabel

enter image description here

回答

2

使用plt.setp

plt.setp(axes[-1], xticks=[5,10,45]) 

shared x

僅供參考,詳細信息,在這裏:
http://matplotlib.org/examples/pylab_examples/shared_axis_demo.html

+0

謝謝!我用這個附加問題更新了OP:我怎樣才能渲染一個適用於所有地塊的居中'ylabel'? (它可能很長,跨越多個子圖的高度) – Josh

+0

只能將它放在中間:'plt.setp(axes [1],ylabel ='hello這是一個跨多個軸的非常長的ylabel' )' – askewchan