3
import matplotlib
import pylab
x=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
y=[2, 4, 6, 8, 10, 12, 14, 16, 18, 20]
plotting=pylab.plot(x,y)
pylab.show(plotting)

The code above (specifically the last line) would pop up the graph below:

The result when the code is run

If I close the graph window, and run the last line (>>>pylab.show(plotting)) again, the graph would not pop up again. Why is that so? The code above was run in Python 2.7.3.

multigoodverse
  • 7,638
  • 19
  • 64
  • 106
  • Did you close the first window? – Igonato Mar 30 '13 at 23:46
  • 1
    @Ignato: Yes, I close the first window after it pops up and that I try to show it again using the show() function but it does not work. – multigoodverse Mar 30 '13 at 23:49
  • 1
    Found [this](http://stackoverflow.com/a/2399978/723891) "With Matplotlib prior to version 1.0.1, show() should only be called once per program..." but "with Matplotlib version 1.0.1+, show() can be called multiple times" is not true, I have 1.1.1 and still can't call it twice. – Igonato Mar 30 '13 at 23:54
  • 1
    @Igonato I think it means 'won't blow up if called more than once'. I think it used to include code that started the GUI main loop. When you close the gui window, there are call backs that remove figure from the structure that `pyplot` uses to keep track of it's figures hence `show` will do nothing if it does not know about any figures to show. – tacaswell Mar 31 '13 at 00:10

1 Answers1

5

Because when you close the window python tears down and deletes the figure. Calling show again does nothing because there is no figure to show.

Passing an arguement to show like you do here does nothing (doc). The only argument that show takes is a key-word argument of block.

tacaswell
  • 84,579
  • 22
  • 210
  • 199