Note that there are some explanatory texts on larger screens.

plurals
  1. POpylab.ion() in python 2, matplotlib 1.1.1 and updating of the plot while the program runs
    primarykey
    data
    text
    <p>what I am trying to do is having a script compute something, prepare a plot and show the already obtained results as a pylab.figure - in python 2 (specifically python 2.7) with a stable matplotlib (which is 1.1.1).</p> <p>In python 3 (python 3.2.3 with a matplotlib git build ... version 1.2.x), this works fine. As a simple example (simulating a lengthy computation by time.sleep()) consider</p> <pre><code>import pylab import time import random dat=[0,1] pylab.plot(dat) pylab.ion() pylab.draw() for i in range (18): dat.append(random.uniform(0,1)) pylab.plot(dat) pylab.draw() time.sleep(1) </code></pre> <p>In python 2 (version 2.7.3 vith matplotlib 1.1.1), the code runs cleanly without errors but does not show the figure. A little trial and error with the python2 interpreter seemed to suggest to replace pylab.draw() with pylab.show(); doing this once is apparently sufficient (not, as with draw calling it after every change/addition to the plot). Hence:</p> <pre><code>import pylab import time import random dat=[0,1] pylab.plot(dat) pylab.ion() pylab.show() for i in range (18): dat.append(random.uniform(0,1)) pylab.plot(dat) #pylab.draw() time.sleep(1) </code></pre> <p>However, this doesn't work either. Again, it runs cleanly but does not show the figure. It seems to do so only when waiting for user input. It is not clear to me why this is, but the plot is finally shown when a raw_input() is added to the loop </p> <pre><code>import pylab import time import random dat=[0,1] pylab.plot(dat) pylab.ion() pylab.show() for i in range (18): dat.append(random.uniform(0,1)) pylab.plot(dat) #pylab.draw() time.sleep(1) raw_input() </code></pre> <p>With this, the script will of course wait for user input while showing the plot and will not continue computing the data before the user hits enter. This was, of course, not the intention.</p> <p>This may be caused by different versions of matplotlib (1.1.1 and 1.2.x) or by different python versions (2.7.3 and 3.2.3).</p> <p>Is there any way to accomplish with python 2 with a stable (1.1.1) matplotlib what the above script (the first one) does in python 3, matplotlib 1.2.x: - computing data (which takes a while, in the above example simulated by time.sleep()) in a loop or iterated function and - (while still computing) showing what has already been computed in previous iterations - and not bothering the user to continually hit enter for the computation to continue</p> <p>Thanks; I'd appreciate any help...</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload