I want to plot a graph and keep it even if the script finished. But it failed after I tried many times.
After script finished executing, the graph created by the show() method will be closed simultaneously.
Code:
import matplotlib.pyplot as plt
plt.scatter([0], [1])
plt.draw()
plt.show(block=False)
for i in range(10): plt.scatter([i], [i+1]) plt.draw() plt.pause(0.001)My version is below:
user@ya:~/$ sudo pip freeze | grep matplotlib
matplotlib==2.2.3
user@ya:~/$ sudo pip -V
pip 18.1 from /usr/local/lib/python2.7/dist-packages/pip (python 2.7)Environments:
I only execute script in Ubuntu ex: user@ya: python xxx.py
Distributor ID: Ubuntu
Description: Ubuntu 16.04.5 LTS
Release: 16.04
Codename: xenialCan anyone help me? I just want to do like Matlab which won't close the plotted graph even if the script finishes.
1 Answer
This is more a question for stackoverflow.com that askubuntu.com
Anyway, the fix is simple. You called plt.show() with block=False. So that's why it exists at the end of the script.
Just add a single line like:
plt.show()at the end of your script and the plot will stay open.
2