I am trying to get an interactive matplotlib plot to run. From the tutorial I tried this code:
import matplotlib.pyplot as plt
plt.ion()
plt.plot([1.6, 2.7])
If I copy it into a shell everything works fine and a window opens.
But if I try to execute the code in a script with python3 script.py after a second it returns back to the shell without showing any window.
It seems that this seems be a popular problem, but no solution I found on the internet was working.
I tried adding plt.show() and plt.draw(), as well a loop so that the program does not immediately exit. But then there is just the python rocket bouncing in my doc indefinitely.
I tried different backends, but the symptoms where the same for all of them.
I installed python3 using homebrew and matplotlib using pip3. I run macOS 10.14.6.
Try to add this
plt.show(block=True)
It works fine for my case.
You could use the python debugging module to do this.
Use plt.ion() before you start plotting.
Then add import pdb; pdb.set_trace() at the point you want to start working interactively.
I use this method a lot for playing around with a complex plot until I'm happy with it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With