how to generate one plot per key press?

The following trivial program is supposed to generate one plot per key press
until the user presses 'q'. Instead, nothing is displayed until the user
presses 'q'. Any suggestions will be appreciated.

from os import sys
from matplotlib import *
from numpy.random import rand

while True:

   z= rand(20,20)
   fig= pyplot.figure(figsize=(8,8), dpi=120)
   pyplot.imshow(z)
   pyplot.show()

   chr= sys.stdin.read(1)
   if chr=='q': sys.exit(0)

···


View this message in context: http://www.nabble.com/how-to-generate-one-plot-per-key-press--tp25100658p25100658.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

Try something like this:

from os import sys
from matplotlib import *
from numpy.random import rand

fig= pyplot.figure(figsize=(8,8), dpi=120)
pyplot.show()
while True:
    z= rand(20,20)
    pyplot.imshow(z)
    pyplot.draw()

    chr= sys.stdin.read(1)
    if chr=='q':
        break

pyplot.close('all')

cheers,
    Paul

Dr. Phillip M. Feldman, on 2009-08-22 23:19, wrote:

···

The following trivial program is supposed to generate one plot per key press
until the user presses 'q'. Instead, nothing is displayed until the user
presses 'q'. Any suggestions will be appreciated.

from os import sys
from matplotlib import *
from numpy.random import rand

while True:

   z= rand(20,20)
   fig= pyplot.figure(figsize=(8,8), dpi=120)
   pyplot.imshow(z)
   pyplot.show()

   chr= sys.stdin.read(1)
   if chr=='q': sys.exit(0)

View this message in context: http://www.nabble.com/how-to-generate-one-plot-per-key-press--tp25100658p25100658.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

appologies - sys.stdin.read(1) blocks until you give it a new line
(<Enter>) that' s probably what you were having problems with.
           
Paul Ivanov, on 2009-08-23 01:14, wrote:

···

Try something like this:

from os import sys
from matplotlib import *
from numpy.random import rand

fig= pyplot.figure(figsize=(8,8), dpi=120)
pyplot.show()
while True:
    z= rand(20,20)
    pyplot.imshow(z)
    pyplot.draw()

    chr= sys.stdin.read(1)
    if chr=='q':
        break

pyplot.close('all')

cheers,
    Paul

Dr. Phillip M. Feldman, on 2009-08-22 23:19, wrote:
>
> The following trivial program is supposed to generate one plot per key press
> until the user presses 'q'. Instead, nothing is displayed until the user
> presses 'q'. Any suggestions will be appreciated.
>
> from os import sys
> from matplotlib import *
> from numpy.random import rand
>
> while True:
>
> z= rand(20,20)
> fig= pyplot.figure(figsize=(8,8), dpi=120)
> pyplot.imshow(z)
> pyplot.show()
>
> chr= sys.stdin.read(1)
> if chr=='q': sys.exit(0)
> –
> View this message in context: http://www.nabble.com/how-to-generate-one-plot-per-key-press--tp25100658p25100658.html
> Sent from the matplotlib - users mailing list archive at Nabble.com.
>
>
> ------------------------------------------------------------------------------
> Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
> trial. Simplify your report design, integration and deployment - and focus on
> what you do best, core application coding. Discover what's new with
> Crystal Reports now. http://p.sf.net/sfu/bobj-july
> _______________________________________________
> Matplotlib-users mailing list
> Matplotlib-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Having to hit Enter is not a major problem, but I'm still not getting
anything displayed.

I noticed that you used pyplot.draw() instead of pyplot.show(). I've
checked the available documentation, but haven't been able to understand the
difference between these.

I should have mentioned that I'm running this script from the IPython
prompt.

Thanks!

···


View this message in context: http://www.nabble.com/how-to-generate-one-plot-per-key-press--tp25100658p25104051.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

Dr. Phillip M. Feldman wrote:

Having to hit Enter is not a major problem, but I'm still not getting
anything displayed.

i guess that might be because the "show" command before the loop blocks
the program.

you can omit the line with "show" or start ipython with
ipython -pylab
both versions work here.

good luck,
sebastian.