Python Forum
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Cannot close matplot figure
#1
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()
Reply
#2
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?
Reply
#3
What about if I want to close it immediately and automatically after plot?
Reply
#4
That is exactly what happens when I run your code on my machine (PyCharm, Python 3.5 x64).
Reply
#5
(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
Reply
#6
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()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Matplot / numpy noisy data problem the57chambers 1 664 Feb-09-2023, 03:27 AM
Last Post: deanhystad
  Error when running a matplot lib example aurelius_nero 3 6,688 Apr-24-2022, 01:24 PM
Last Post: Axel_Erfurt
  How to save Matplot chart to temp file? Morkus 2 4,435 Jun-12-2021, 10:52 AM
Last Post: Morkus
  remove weekends from matplot mr_byte31 3 4,431 Aug-10-2019, 08:37 AM
Last Post: DeaD_EyE
  Generate matplot animation on a link ambush 0 2,132 Apr-01-2019, 10:23 AM
Last Post: ambush

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020