On Tuesday, June 29, 2010 03:32:00 pm ninjasmith wrote:
> hi there,
> 
> I've got a bit stuck with running matplotlib in interactive mode.  maybe
> what I want to do can't be done easily.
> 
> want I want is a simple python script which I can run with a file argument.
> this will then create some plots.  the script will wait for user input (via
> sys.stdin.readline()), use the input to adjust a threshold and replot my
> plots.  after the user is satisfied with the thresholds the script exit the
> loop and will perform other processing.  Basically I'm trying to get a
> simple interactive program with plots but without having use wxpython or
> simliar
> 
> I have been trying to test the potting part of this.
> 
> I have successfully set interactive mode on and from the python interpreter
> I can plot and I see my plots and updates to them without needing to use
> pyplot.show().
> 
> when I run the same scripts by using 'python scriptname.py' I don't see the
> plots unless I use pyplot.show().
> 
> my simple test script is as follows
> 
> ############
> #test interactive matplotlib plotting
> 
> import numpy as np
> import sys
> import matplotlib.pylab as pyp
> 
> a=np.array([0,4,5,5,3,4,5])
> pyp.figure()
> pyp.plot(a)
> #pyp.show()
> input=sys.stdin.readline()
> pyp.xlabel('my xlabel %s' %input)
> input=sys.stdin.readline()
> 
> any help much appreciated

Hi,

I think what you are after is the interactive mode of matplotlib. You can turn 
is on by "ion" and redraw the current figure using "draw". In ipythons "pylab" 
mode this is done implicit. I attached some example lines which guide you to 
the right direction. I'm not sure why I need two draws in my attached script, 
but at least it seems to do the job.
For more infos you may visit: 
http://matplotlib.sourceforge.net/users/shell.html#controlling-interactive-
updating

Kind regards,
Matthias

import numpy as np
import sys
import matplotlib.pylab as pyp

a = np.array([0, 4, 5, 5, 3, 4, 5])
pyp.ion()
pyp.figure()
pyp.plot(a)
pyp.draw()
pyp.draw()

input = sys.stdin.readline()
print "input 1 : %s " % (input)
pyp.xlabel('my xlabel %s' % input)
pyp.draw()
pyp.draw()

input = sys.stdin.readline()
print "input 2 : %s " % (input)

pyp.ioff()
pyp.show()
------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to