2013-05-22 73 views
1

我必須在我的圖中繪製3個不同通道的eeg數據。我想在一個由horozintal線分隔的數字中繪製所有這些圖。所有通道共同的X軸。在matplotlib中添加一條與三個不同軸交叉的垂直線

我可以通過使用add_axes輕鬆完成此操作。但是我想繪製一條與這些軸相交的垂直線。但我無法做到這一點。

目前,我的示例代碼如下所示。

from pylab import figure, show, setp 
from numpy import sin, cos, exp, pi, arange 

t = arange(0.0, 2.0, 0.01) 
s1 = sin(2*pi*t) 
s2 = exp(-t) 
s3 = 200*t 



fig = figure() 
t = arange(0.0, 2.0, 0.01) 

yprops = dict(rotation=0, 
       horizontalalignment='right', 
       verticalalignment='center', 
       x=-0.1) 

axprops = dict(yticks=[]) 

ax1 =fig.add_axes([0.1, 0.5, 0.8, 0.2], **axprops) 
ax1.plot(t, s1) 
ax1.set_ylabel('S1', **yprops) 

axprops['sharex'] = ax1 
#axprops['sharey'] = ax1 
# force x axes to remain in register, even with toolbar navigation 
ax2 = fig.add_axes([0.1, 0.3, 0.8, 0.2], **axprops) 

ax2.plot(t, s2) 
ax2.set_ylabel('S2', **yprops) 

ax3 = fig.add_axes([0.1, 0.1, 0.8, 0.2], **axprops) 
ax3.plot(t, s3) 
ax3.set_ylabel('S3', **yprops) 




# turn off x ticklabels for all but the lower axes 
for ax in ax1, ax2: 
    setp(ax.get_xticklabels(), visible=False) 

show() 

我希望我的最終圖像看起來像下面那樣。在我目前的輸出中,我可以得到沒有綠色垂直線的同一個圖。

enter image description here

任何一個可以請幫助???我不想使用subplots,也不想爲每個軸添加axvline。

謝謝U, thothadri

回答

1

使用

vl_lst = [a.axvline(x_pos, color='g', lw=3, linestyle='-') for a in [ax1, ax2, ax3]] 

更新每個幀:

new_x = X 
for v in vl_lst: 
    v.set_xdata(new_x) 

axvline doc

+0

其實,我知道的作品。但我不想爲每個子軸單獨添加。 –

+0

因爲,我嘗試以0.33秒的速度在x軸上對綠線進行動畫處理。所以每次都必須爲每個軸畫出獨立的線條,這可能會導致更多的計算能力 –

+1

@ThothadriRajesh藝術家被附加到軸上。與一位藝術家一起繪製三個軸看起來對我來說很危險。 – tacaswell