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 !

1 Answer 1

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()
Sign up to request clarification or add additional context in comments.

1 Comment

Well, I always use arrays, so I forgot that lists could solve the problem. Thank you very much, it works !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.