Here is a script that solves the problem, based on Goyo's input:
**
#!/usr/bin/env python
"""simple_matplot.py --
Repeatedly plots sinusoids (shifted a bit each time).
- control returns to the user after each plot;
- the old plot is erased between cycles.
"""
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
x = np.arange(0.,2.*np.pi,0.02)
y = np.sin(x)
c = "go"
plt.ion()
fig = plt.figure()
ax = fig.add_subplot(1,1,1)
while c.find("go") > -1 :
try:
del ax.lines[0]
except :
pass
line, = ax.plot(x,y,'-')
plt.draw()
print "stop or go?"
c = raw_input()
x = x + 0.5
**
John Thorstensen wrote:
>
> I have a sizeable number of python data-inspection scripts that work as
> follows:
>
> - read some data, or do something with it
> - plot the data
> - query the user on the command line and get a response
> - do what the user commands.
>
> These use the venerable PGPLOT package for the graphics, but this has been
> static for years and is getting increasingly vulnerable to obsolescence of
> the supporting packages (e.g., numarray).
>
> I'm having a hard time converting these scripts to matplotlib because when
> you do a show(), the mainloop takes over. It's possible to work around by
> doing a show() for every plot, and then killing the plot manually, but
> after a couple of hundred manual kills this gets tiresome. It would also
> be possible to restructure the code so that the various options get
> controlled by key press events in the plot, I suppose, but the effort
> involved in converting all the scripts would be pretty large.
>
> So my question: Is there a simple way of getting matplotlib to display a
> plot in a window and then surrender control to the main program, without
> destroying the plot? Something like a method to kill mainloop would be
> ideal.
>
> Thanks.
>
> [Apologies if this is general knowledge -- I couldn't find an answer.]
>
--
View this message in context:
http://old.nabble.com/Non-interactive-plotting-to-window--tp32981792p32987821.html
Sent from the matplotlib - users mailing list archive at Nabble.com.
--
Learn Windows Azure Live! Tuesday, Dec 13, 2011
Microsoft is holding a special Learn Windows Azure training event for
developers. It will provide a great way to learn Windows Azure and what it
provides. You can attend the event by watching it streamed LIVE online.
Learn more at http://p.sf.net/sfu/ms-windowsazure
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users