1

I have a subplot in python matplotlib,and I want to determine the other subplot based on observations of this subplot. I want to see two subplots, one empty, and after observing the nonempty one, determine an input, input it from the keyboard and have the second subplot generated in the empty space next to the first one. Also maybe do this multiple times reusing the initially empty subplot. What is the best way to do this kind of interactive plot

subplot(1,2,1)

plt.plot(x_range,points,'o')

plt.subplot(1,2,2)
#maybe plot some prompt in the second subplot

plt.show()
#proceed, clean plot

subplot(1,2,1)

plt.plot(x_range,points,'o')

point_chosen = input("choose a point: ")
#checking validity
plt.bar(range(x), y(point_chosen))
plt.show()

I didn't manage to stop the plot as well, plt.show() was blocking. If I used plot.ion() at the beginning it would immediately close the plotting windows.

1 Answer 1

1

I'm not sure if this is really what you want, but turning interactive mode off after the input will let your figure stay.

import matplotlib.pyplot as plt
x_range = list(range(10))
points = list(range(10))

plt.ion()

plt.subplot(1,2,1)

plt.plot(x_range,points,'o')

plt.subplot(1,2,2)
#maybe plot some prompt in the second subplot

plt.show()
#procceed, clean plot


point_chosen = input("choose a point: ")
#checking validty
plt.subplot(1,2,2)
plt.plot(x_range,points,'o')
plt.bar(x_range[point_chosen], points[point_chosen])

plt.ioff()
plt.show()
Sign up to request clarification or add additional context in comments.

Comments

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.