0

I'm trying to use a multicursor in matplotlib as in the example here. The problem is that my subplots are loop-generated, which means I don't have an ax1, ax2,... But a code is worth a thousands words :

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()

Does anyone have an idea ? Thanks !

4

1 回答 1

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()
于 2016-05-19T17:50:48.147 回答