2 simple ??: program exit w/graph, update graph real-time

Hi,

I have two quick questions:

1. Is it possible to exit a Python program but still have the graph
window generated by pylot remain visible? Right now the program stops
when I display the (only) final graph. When I close this window, the
program exits. I would like to finish the program, but have the graph
stay visible if that's possible (I suppose I could save a graphics
file and then display it - but that's a bit different)

2. Is it possible to update graphs somewhat efficiently during the
runtime of the program? Say I have a loop that generates value to
be plotted. Right now I collect them and plot them at the end, ie

values = []
for i in range(0, 200):
     values.append(i)

various pyplot commands to plot the values list.

I wonder if I could have the graph update during each iteration instead
giving me an up-to-date view of the data. (The above is a super simplified
example of course)

Thanks,
Esmail

Try this:

http://matplotlib.sourceforge.net/examples/animation/simple_anim_gtk.html

(If not gtk, there are other examples there.)

Ryan

···

On Thu, Apr 23, 2009 at 1:04 PM, Esmail <ebonak@…32…> wrote:

Hi,

I have two quick questions:

  1. Is it possible to exit a Python program but still have the graph

window generated by pylot remain visible? Right now the program stops

when I display the (only) final graph. When I close this window, the

program exits. I would like to finish the program, but have the graph

stay visible if that’s possible (I suppose I could save a graphics

file and then display it - but that’s a bit different)

  1. Is it possible to update graphs somewhat efficiently during the

runtime of the program? Say I have a loop that generates value to

be plotted. Right now I collect them and plot them at the end, ie

values =

for i in range(0, 200):

 values.append(i)

various pyplot commands to plot the values list.

I wonder if I could have the graph update during each iteration instead

giving me an up-to-date view of the data. (The above is a super simplified

example of course)


Ryan May
Graduate Research Assistant
School of Meteorology
University of Oklahoma

Ryan May wrote:

Try this:

http://matplotlib.sourceforge.net/examples/animation/simple_anim_gtk.html

(If not gtk, there are other examples there.)

Thanks Ryan, that'll give me some idea with regard to the animation,
and real-time drawings.

Any idea if it's possible to finish a Python program but still have the
graph showing?

FWIW, I'm doing this under Linux.

Thanks,
Esmail

You’d have to run the plotting in a separate process from the computation. subprocess would let you do that, assuming you can spin off a child task that stays alive when the parent exits. You’d also need to get the computing process to give new results to the child plot, maybe using a pipe (which I think subprocess can handle as well.)

Ryan

···

On Thu, Apr 23, 2009 at 4:16 PM, Esmail <ebonak@…32…> wrote:

Ryan May wrote:

Try this:

http://matplotlib.sourceforge.net/examples/animation/simple_anim_gtk.html

(If not gtk, there are other examples there.)

Thanks Ryan, that’ll give me some idea with regard to the animation,

and real-time drawings.

Any idea if it’s possible to finish a Python program but still have the

graph showing?

FWIW, I’m doing this under Linux.


Ryan May
Graduate Research Assistant
School of Meteorology
University of Oklahoma
Sent from Norman, Oklahoma, United States

Hi Ryan,

Ryan May wrote:

···

On Thu, Apr 23, 2009 at 4:16 PM, Esmail <ebonak@...32...> wrote:

Ryan May wrote:

Try this:

http://matplotlib.sourceforge.net/examples/animation/simple_anim_gtk.html

(If not gtk, there are other examples there.)

Thanks Ryan, that'll give me some idea with regard to the animation,
and real-time drawings.

Any idea if it's possible to finish a Python program but still have the
graph showing?

FWIW, I'm doing this under Linux.

You'd have to run the plotting in a separate process from the computation.
subprocess would let you do that, assuming you can spin off a child task
that stays alive when the parent exits. You'd also need to get the
computing process to give new results to the child plot, maybe using a pipe
(which I think subprocess can handle as well.)

This is exactly what I have tried/described in [1], using the multiprocessing module. It sort of works, but I have that hanging problem at the end - maybe somebody jumps in and helps this time :slight_smile:

r.

[1] [Matplotlib-users] plotting in a separate process

Ryan May wrote:

    Any idea if it's possible to finish a Python program but still have the
    graph showing?

    FWIW, I'm doing this under Linux.

You'd have to run the plotting in a separate process from the computation. subprocess would let you do that, assuming you can spin off a child task that stays alive when the parent exits. You'd also need to get the computing process to give new results to the child plot, maybe using a pipe (which I think subprocess can handle as well.)

Thanks Ryan, I have been meaning to explore Python's
threading/multi-processing facilities, so this will provide a
good excuse to do so :slight_smile: [when I find the time... so much to learn,
so little time]

Robert Cimrman wrote:

This is exactly what I have tried/described in [1], using the multiprocessing module. It sort of works, but I have that hanging problem at the end - maybe somebody jumps in and helps this time :slight_smile:

r.

[1] [Matplotlib-users] plotting in a separate process

Hi,

Sounds interesting, but I get a "page not found 404" type error when
I follow this link.

Esmail

Esmail wrote:

Robert Cimrman wrote:

This is exactly what I have tried/described in [1], using the multiprocessing module. It sort of works, but I have that hanging problem at the end - maybe somebody jumps in and helps this time :slight_smile:

r.

[1] [Matplotlib-users] plotting in a separate process

Hi,

Sounds interesting, but I get a "page not found 404" type error when
I follow this link.

Strange, it does work for me. Alternatively, just search
"[Matplotlib-users] plotting in a separate process" in google...

r.

I was curious, so I cooked up a quick demo using two scripts. Put them in the same directory and run datasource.py. It’s not perfect, and I think the use of raw_input() is a little odd, but it works.

Ryan

datasource.py (251 Bytes)

plotter.py (908 Bytes)

···

On Fri, Apr 24, 2009 at 5:52 AM, Esmail <ebonak@…32…> wrote:

Ryan May wrote:

Any idea if it's possible to finish a Python program but still have the
graph showing?
FWIW, I'm doing this under Linux.

You’d have to run the plotting in a separate process from the

computation. subprocess would let you do that, assuming you can spin

off a child task that stays alive when the parent exits. You’d also

need to get the computing process to give new results to the child plot,

maybe using a pipe (which I think subprocess can handle as well.)

Thanks Ryan, I have been meaning to explore Python’s

threading/multi-processing facilities, so this will provide a

good excuse to do so :slight_smile: [when I find the time… so much to learn,

so little time]


Ryan May
Graduate Research Assistant
School of Meteorology
University of Oklahoma
Sent from Norman, Oklahoma, United States

Ryan May wrote:

···

On Fri, Apr 24, 2009 at 5:52 AM, Esmail <ebonak@...32...> wrote:

Ryan May wrote:

    Any idea if it's possible to finish a Python program but still have

the

    graph showing?

    FWIW, I'm doing this under Linux.

You'd have to run the plotting in a separate process from the
computation. subprocess would let you do that, assuming you can spin
off a child task that stays alive when the parent exits. You'd also
need to get the computing process to give new results to the child plot,
maybe using a pipe (which I think subprocess can handle as well.)

Thanks Ryan, I have been meaning to explore Python's
threading/multi-processing facilities, so this will provide a
good excuse to do so :slight_smile: [when I find the time... so much to learn,
so little time]

I was curious, so I cooked up a quick demo using two scripts. Put them in
the same directory and run datasource.py. It's not perfect, and I think the
use of raw_input() is a little odd, but it works.

Nice! I will try using the subprocess module instead of multiprocessing, as your example works for me.

Thanks!
r.

Robert Cimrman wrote:

Sounds interesting, but I get a "page not found 404" type error when
I follow this link.

Strange, it does work for me. Alternatively, just search
"[Matplotlib-users] plotting in a separate process" in google...

Thanks Robert, I'll give that a try.

Esmail

Ryan May wrote:

I was curious, so I cooked up a quick demo using two scripts. Put them in the same directory and run datasource.py. It's not perfect, and I think the use of raw_input() is a little odd, but it works.

Very cool Ryan, thanks for doing that, I plan on studying your code
this weekend.

Cheers,
Esmail

Robert Cimrman wrote:

Hi Ryan,

Ryan May wrote:

Ryan May wrote:

Try this:

http://matplotlib.sourceforge.net/examples/animation/simple_anim_gtk.html

(If not gtk, there are other examples there.)

Thanks Ryan, that'll give me some idea with regard to the animation,
and real-time drawings.

Any idea if it's possible to finish a Python program but still have the
graph showing?

FWIW, I'm doing this under Linux.

You'd have to run the plotting in a separate process from the computation.
subprocess would let you do that, assuming you can spin off a child task
that stays alive when the parent exits. You'd also need to get the
computing process to give new results to the child plot, maybe using a pipe
(which I think subprocess can handle as well.)

This is exactly what I have tried/described in [1], using the multiprocessing module. It sort of works, but I have that hanging problem at the end - maybe somebody jumps in and helps this time :slight_smile:

r.

[1] [Matplotlib-users] plotting in a separate process

Just for the record: Ryan May's example in this thread, that uses pipes, inspired me to try pipes as well, instead of queues (multiprocessing.Pipe instead of Queue) and the "hanging problem", i.e. the problem that Ctrl-C interrupted the program, but it had to be killed to stop, disappeared. I can fix the script that I sent in message [1] and provide it, if there is interest. (Currently I have fixed only the version that is within sfepy).

thanks!
r.

[1] [Matplotlib-users] plotting in a separate process, 31.03.2009

···

On Thu, Apr 23, 2009 at 4:16 PM, Esmail <ebonak@...32...> wrote:

I’d like to see it ;>

···

On Wed, May 6, 2009 at 8:57 AM, Robert Cimrman <cimrman3@…1098…> wrote:

Robert Cimrman wrote:

Hi Ryan,

Ryan May wrote:

On Thu, Apr 23, 2009 at 4:16 PM, Esmail <ebonak@…32…> wrote:

Ryan May wrote:

Try this:

http://matplotlib.sourceforge.net/examples/animation/simple_anim_gtk.html

(If not gtk, there are other examples there.)

Thanks Ryan, that’ll give me some idea with regard to the animation,

and real-time drawings.

Any idea if it’s possible to finish a Python program but still have the

graph showing?

FWIW, I’m doing this under Linux.

You’d have to run the plotting in a separate process from the computation.

subprocess would let you do that, assuming you can spin off a child task

that stays alive when the parent exits. You’d also need to get the

computing process to give new results to the child plot, maybe using a pipe

(which I think subprocess can handle as well.)

This is exactly what I have tried/described in [1], using the

multiprocessing module. It sort of works, but I have that hanging

problem at the end - maybe somebody jumps in and helps this time :slight_smile:

r.

[1]

http://www.mail-archive.com/matplotlib-users@lists.sourceforge.net/msg10873.html

Just for the record: Ryan May’s example in this thread, that uses pipes,

inspired me to try pipes as well, instead of queues

(multiprocessing.Pipe instead of Queue) and the “hanging problem”, i.e.

the problem that Ctrl-C interrupted the program, but it had to be killed

to stop, disappeared. I can fix the script that I sent in message [1]

and provide it, if there is interest. (Currently I have fixed only the

version that is within sfepy).

thanks!

r.

[1] [Matplotlib-users] plotting in a separate process, 31.03.2009


The NEW KODAK i700 Series Scanners deliver under ANY circumstances! Your

production scanning environment may not be a perfect world - but thanks to

Kodak, there’s a perfect scanner to get the job done! With the NEW KODAK i700

Series Scanner you’ll get full speed at 300 dpi even with all image

processing features enabled. http://p.sf.net/sfu/kodak-com


Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users

william ratcliff wrote:

I'd like to see it ;>

Here you are...

r.

log.py (1.79 KB)

I know I’d be interested. With your permission, it might make a nice example as well.

Ryan

···

On Wed, May 6, 2009 at 7:57 AM, Robert Cimrman <cimrman3@…2594…8…> wrote:

Robert Cimrman wrote:

Hi Ryan,

Ryan May wrote:

On Thu, Apr 23, 2009 at 4:16 PM, Esmail <ebonak@…32…> wrote:

Ryan May wrote:

Try this:

http://matplotlib.sourceforge.net/examples/animation/simple_anim_gtk.html

(If not gtk, there are other examples there.)

Thanks Ryan, that’ll give me some idea with regard to the animation,

and real-time drawings.

Any idea if it’s possible to finish a Python program but still have the

graph showing?

FWIW, I’m doing this under Linux.

You’d have to run the plotting in a separate process from the computation.

subprocess would let you do that, assuming you can spin off a child task

that stays alive when the parent exits. You’d also need to get the

computing process to give new results to the child plot, maybe using a pipe

(which I think subprocess can handle as well.)

This is exactly what I have tried/described in [1], using the

multiprocessing module. It sort of works, but I have that hanging

problem at the end - maybe somebody jumps in and helps this time :slight_smile:

r.

[1]

http://www.mail-archive.com/matplotlib-users@lists.sourceforge.net/msg10873.html

Just for the record: Ryan May’s example in this thread, that uses pipes,

inspired me to try pipes as well, instead of queues

(multiprocessing.Pipe instead of Queue) and the “hanging problem”, i.e.

the problem that Ctrl-C interrupted the program, but it had to be killed

to stop, disappeared. I can fix the script that I sent in message [1]

and provide it, if there is interest. (Currently I have fixed only the

version that is within sfepy).


Ryan May
Graduate Research Assistant

School of Meteorology
University of Oklahoma
Sent from Norman, Oklahoma, United States

Ryan May wrote:

···

On Wed, May 6, 2009 at 7:57 AM, Robert Cimrman <cimrman3@...1098...> wrote:

Just for the record: Ryan May's example in this thread, that uses pipes,
inspired me to try pipes as well, instead of queues
(multiprocessing.Pipe instead of Queue) and the "hanging problem", i.e.
the problem that Ctrl-C interrupted the program, but it had to be killed
to stop, disappeared. I can fix the script that I sent in message [1]
and provide it, if there is interest. (Currently I have fixed only the
version that is within sfepy).

I know I'd be interested. With your permission, it might make a nice
example as well.

Permission granted :slight_smile: I have sent the script in response to William.

r.

Done. I like the fact that with your example, everything is self-contained in a single script.

Ryan

···

On Wed, May 6, 2009 at 8:53 AM, Robert Cimrman <cimrman3@…2594…8…> wrote:

Ryan May wrote:

On Wed, May 6, 2009 at 7:57 AM, Robert Cimrman <cimrman3@…1098…> wrote:

Just for the record: Ryan May’s example in this thread, that uses pipes,

inspired me to try pipes as well, instead of queues

(multiprocessing.Pipe instead of Queue) and the “hanging problem”, i.e.

the problem that Ctrl-C interrupted the program, but it had to be killed

to stop, disappeared. I can fix the script that I sent in message [1]

and provide it, if there is interest. (Currently I have fixed only the

version that is within sfepy).

I know I’d be interested. With your permission, it might make a nice

example as well.

Permission granted :slight_smile: I have sent the script in response to William.


Ryan May
Graduate Research Assistant

School of Meteorology
University of Oklahoma
Sent from Norman, Oklahoma, United States

Ryan May wrote:

Ryan May wrote:

Just for the record: Ryan May's example in this thread, that uses pipes,
inspired me to try pipes as well, instead of queues
(multiprocessing.Pipe instead of Queue) and the "hanging problem", i.e.
the problem that Ctrl-C interrupted the program, but it had to be killed
to stop, disappeared. I can fix the script that I sent in message [1]
and provide it, if there is interest. (Currently I have fixed only the
version that is within sfepy).

I know I'd be interested. With your permission, it might make a nice
example as well.

Permission granted :slight_smile: I have sent the script in response to William.

Done. I like the fact that with your example, everything is self-contained
in a single script.

Exactly, the details of starting another python process are hidden, the multiprocessing module is really nice.

You might want to add

import matplotlib
matplotlib.use('GtkAgg')

to the script, and remove "from Queue import Empty".

FYI: I am sending also a more complex example - a Log class used in sfepy, which supports multiple subplots, labels, logarithmic plots etc. The file contains some other support classes too, so that it works standalone. It is not very polished, but it serves its purpose.

r.

log2.py (13.2 KB)

···

On Wed, May 6, 2009 at 8:53 AM, Robert Cimrman <cimrman3@...1098...> wrote:

On Wed, May 6, 2009 at 7:57 AM, Robert Cimrman <cimrman3@...1098...> >>> wrote:

Robert Cimrman wrote:

Ryan May wrote:

Ryan May wrote:

In case you are not receiving the automatic svn commit messages: yesterday I took the liberty of renaming log.py to multiprocess.py, because as far as I could see the former gave no clue as to the point of the example. Feel free to change it back, or change it to something else, if you think I am mistaken or confused about this.

Eric

···

On Wed, May 6, 2009 at 8:53 AM, Robert Cimrman <cimrman3@...1098...> >> wrote:

On Wed, May 6, 2009 at 7:57 AM, Robert Cimrman <cimrman3@...1098...> >>>> wrote:

Just for the record: Ryan May's example in this thread, that uses pipes,
inspired me to try pipes as well, instead of queues
(multiprocessing.Pipe instead of Queue) and the "hanging problem", i.e.
the problem that Ctrl-C interrupted the program, but it had to be killed
to stop, disappeared. I can fix the script that I sent in message [1]
and provide it, if there is interest. (Currently I have fixed only the
version that is within sfepy).

I know I'd be interested. With your permission, it might make a nice
example as well.

Permission granted :slight_smile: I have sent the script in response to William.

Done. I like the fact that with your example, everything is self-contained
in a single script.

Exactly, the details of starting another python process are hidden, the multiprocessing module is really nice.

You might want to add

import matplotlib
matplotlib.use('GtkAgg')

to the script, and remove "from Queue import Empty".

FYI: I am sending also a more complex example - a Log class used in sfepy, which supports multiple subplots, labels, logarithmic plots etc. The file contains some other support classes too, so that it works standalone. It is not very polished, but it serves its purpose.

r.

------------------------------------------------------------------------

------------------------------------------------------------------------------
The NEW KODAK i700 Series Scanners deliver under ANY circumstances! Your
production scanning environment may not be a perfect world - but thanks to
Kodak, there's a perfect scanner to get the job done! With the NEW KODAK i700
Series Scanner you'll get full speed at 300 dpi even with all image processing features enabled. http://p.sf.net/sfu/kodak-com

------------------------------------------------------------------------

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options