2016-05-19 32 views
0

我試圖在示例here的示例中使用matplotlib中的多光標。 的問題是,我的次要情節是循環產生的,這意味着我沒有一個AX1,AX2,... 但代碼是值得千字遺言:用於循環生成的子圖的Matplotlib multicursor.py

t = 0 
fig = plt.figure() 
while t < 16 : 
    ax = fig.add_subplot(4,4,t+1) 
    p1 = plot(...) 
    p2 = plot(...) 
    p3 = plot(...) 
    p4 = plot(...) 
    t = t+1 
show() 

有沒有人有一個想法?謝謝 !

回答

1

爲什麼不製作軸列表並將其傳遞給多光標?

t = 0 
fig = plt.figure() 
axes_list = [] 
while t < 16 : 
    ax = fig.add_subplot(4,4,t+1) 
    axes_list.append(ax) 
    p1 = plot(...) 
    p2 = plot(...) 
    p3 = plot(...) 
    p4 = plot(...) 
    t = t+1 
multi = MultiCursor(fig.canvas, axes_list, color='r', lw=1) 
show() 
+0

嗯,我總是使用數組,所以我忘記列表可以解決問題。非常感謝,它的作品! – FKRZ