This is a MWE of what I\'m after, adapted from this question:
from matplotlib.pyplot import plot, draw, show
def make_plot():
plot([1,2,3])
draw()
None of the presented solutions work for me. I tested them with three different IDEs PyCharm, Spyder and Pyzo, using the (currently) latest Matplotlib 2.1 under Python 3.6.
What works for me, although not optimal, is to use a plt.pause
command:
import matplotlib.pyplot as plt
def make_plot():
plt.plot([1, 2, 3])
# plt.show(block=False) # The plot does not appear.
# plt.draw() # The plot does not appear.
plt.pause(0.1) # The plot properly appears.
print('continue computation')
print('Do something before plotting.')
# Now display plot in a window
make_plot()
answer = input('Back to main and window visible? ')
if answer == 'y':
print('Excellent')
else:
print('Nope')