Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make the plot not disappear?

Suppose you need to store the figure and subplot in variables (to later modify attributes). How can you make the whole figure to stay and not quickly disappear after some millisecs?

import matplotlib.pyplot as plt

fig = plt.figure() 

ax = fig.add_subplot(2,2,1)
ax.plot(1)

fig.show()
like image 876
ritter Avatar asked Sep 11 '12 12:09

ritter


People also ask

How do I stop the plot showing in Matplotlib?

We can simply save plots generated from Matplotlib using savefig() and imsave() methods. If we are in interactive mode, the plot might get displayed. To avoid the display of plot we use close() and ioff() methods.

How do you stop plotting in Python?

You can either (a) allow blocking on your last plot, or (b) don't exit the script (perhaps ask for input: "press <Enter> to exit plot" or something like that).


1 Answers

Change fig to plt:

plt.show()
like image 189
ritter Avatar answered Sep 27 '22 18:09

ritter