Python Forum

Full Version: Cannot close matplot figure
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I thought it should be easy, but I couldn't get to close my figure.

My code:
import matplotlib.pyplot as plt
x=[1,2,3]
y=[5,7,4]
x2=[1,2,3]
y2=[10,14,12]
plt.plot(x,y,label="First Line")
plt.plot(x2,y2,label='Second Line')
plt.xlabel('Plot Number')
plt.ylabel('Important var')
plt.title('Interesting Graph\nCheck it out')
plt.legend()
plt.show()
plt.close()
You would like the figure to appear and then get closed with "plt.close()"? I copied your exact code and for me it works like that. Or is there something else?
What about if I want to close it immediately and automatically after plot?
That is exactly what happens when I run your code on my machine (PyCharm, Python 3.5 x64).
(Jan-10-2017, 08:01 PM)j.crater Wrote: [ -> ]That is exactly what happens when I run your code on my machine (PyCharm, Python 3.5 x64).

Strange. Does not work for me. I am using Python 3.5 with Eclipse
I also cannot close the window
Here is my code

import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import time

im = mpimg.imread('image_001.png')

img = plt.imshow(im)

plt.show()

time.sleep(5)

plt.close()