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 !

FKRZ
  • 3
  • 3

1 Answers1

1

Why not make a list of axes and pass this to the multicursor?

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()
titusjan
  • 5,376
  • 2
  • 24
  • 43
  • Well, I always use arrays, so I forgot that lists could solve the problem. Thank you very much, it works ! – FKRZ May 20 '16 at 07:24