Re: [Matplotlib-users] Fwd: Re: Autonomous display of image/plot/figure

2008-07-15 Thread James K. Gruetzner
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On Monday 14 July 2008 21:22:31 you wrote:
  I would think that the gtk mainloop would terminate when the window
  closes (which termination should propagate back up the stack), but
  apparently that doesn't happen.
 
  I'm not sure I'm following you at the moment.  Are you calling show()
  once and closing the figure doesn't cause it to return?   or are you
  trying to call show() multiple times from a single script and subsequent
  calls to show() fail to return?
 
  Hi, Ryan,
 
  Thanks for your continued help.
 
  I am calling show() once, and closing the figure doesn't cause it to
  return? I've verified the lack of return using debug  sys.stderr.write()
  statements, as well as by following  show()  with a sys.exit() command.

 (Getting this back on the full list...)

 This sounds like a bug to me, specific to your set up.  I just ran a
 script (for my own sanity) and closing the figure, resulted in the
 script exiting and returning to the command prompt.  Do you happen to
 have a small complete example that replicates your problems that you
 could post here?

 Also, what are your versions of matplotlib and PyGtk (you are using
 GtkAgg, right)? Also, what OS are you running?

 Devs, what do you think?

 Ryan
 --
 Ryan May
 Graduate Research Assistant
 School of Meteorology
 University of Oklahoma

Thanks, Ryan,  The requested info is below.
Thanks again.
James

- - SMALL COMPLETE EXAMPLE CODE FOLLOWS -
#!/usr/bin/python
#  File:  test.py

import os,sys
import pylab as PL
import numpy as N

def main():
  fig = PL.figure(1)
  x = N.arange(120.0)*2*N.pi/120.0
  x = PL.resize(x, (100,120))
  y = N.arange(100.0)*2*N.pi/100.0
  y = N.resize(y, (120,100))
  y = N.transpose(y)
  z = N.sin(x) + N.cos(y)
  PL.imshow( z , cmap=PL.cm.jet)#, interpolation='nearest')
  sys.stderr.write(Begun.)
  PL.show()
  sys.stderr.write(Done.)
  sys.exit(0)

if __name__ == __main__:
-  END OF SAMPLE CODE ---

Sample output:
- --- BEGIN --
$ ./test.py
Begun.
- --- COMMENTS: --
  The image displays.
   I click on the X; the image disappears.
  Nothing happens in the terminal output. 
  In the terminal window I type ctrlC.
- --- BEGIN --
^CTraceback (most recent call last):
  File ./test.py, line 59, in module
main()
  File ./test.py, line 25, in main
PL.show()
  File /usr/lib/python2.5/site-packages/matplotlib/backends/backend_gtk.py, 
line 71, in show
gtk.main()
KeyboardInterrupt
$
- -- END OF OUTPUT CODE --

The same behavior occurs when run from within an interactive session.

python version:  2.5.1 (4251:54863, Jun 15 2008, 23:59:20)
Matplotlib version:  0.91.2
PyGTK version:  2.12.0-2.fc8
In ~/.matplotlib/matplotlibrc:   backend  : GTKAgg
OS:  Fedora 8
Linux kernel:  2.6.25.6-27.fc8




-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.7 (GNU/Linux)

iD8DBQFIfKh4xOXthSHeGJIRAvbzAKCF9U7EJ4oM2JyQjKokOBZAv6PSlwCfZV3t
I5jSycQj8dAqI0QGkewAw3o=
=vdPu
-END PGP SIGNATURE-


-
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK  win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100url=/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Fwd: Re: Autonomous display of image/plot/figure

2008-07-15 Thread John Hunter
On Tue, Jul 15, 2008 at 8:39 AM, James K. Gruetzner [EMAIL PROTECTED] wrote:
 -BEGIN PGP SIGNED MESSAGE-
 Hash: SHA1

 On Monday 14 July 2008 21:22:31 you wrote:
  I would think that the gtk mainloop would terminate when the window
  closes (which termination should propagate back up the stack), but
  apparently that doesn't happen.
 
  I'm not sure I'm following you at the moment.  Are you calling show()
  once and closing the figure doesn't cause it to return?   or are you
  trying to call show() multiple times from a single script and subsequent
  calls to show() fail to return?
 
  Hi, Ryan,
 
  Thanks for your continued help.
 
  I am calling show() once, and closing the figure doesn't cause it to
  return? I've verified the lack of return using debug  sys.stderr.write()
  statements, as well as by following  show()  with a sys.exit() command.

 (Getting this back on the full list...)

 This sounds like a bug to me, specific to your set up.  I just ran a
 script (for my own sanity) and closing the figure, resulted in the
 script exiting and returning to the command prompt.  Do you happen to
 have a small complete example that replicates your problems that you
 could post here?

 Also, what are your versions of matplotlib and PyGtk (you are using
 GtkAgg, right)? Also, what OS are you running?

 Devs, what do you think?

 Ryan
 --
 Ryan May
 Graduate Research Assistant
 School of Meteorology
 University of Oklahoma

 Thanks, Ryan,  The requested info is below.
 Thanks again.

I am not seeing any problems on the 91 branch or the 98 trunk.  Below
is my command and output (the shell returns when I close the window
with a click)

[EMAIL PROTECTED]:svn python ~/test.py --verbose-helpful -dGTKAgg
$HOME=/home/titan/johnh
CONFIGDIR=/home/titan/johnh/.matplotlib
matplotlib data path
/home/titan/johnh/dev/lib/python2.4/site-packages/matplotlib/mpl-data
loaded rc file /home/titan/johnh/.matplotlib/matplotlibrc
matplotlib version 0.91.4
verbose.level helpful
interactive is False
units is False
platform is sunos5
numerix numpy 1.2.0.dev5410
Using fontManager instance from /home/titan/johnh/.matplotlib/fontManager.cache
backend GTKAgg version 2.6.0
[EMAIL PROTECTED]:svn

-
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK  win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100url=/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Fwd: Re: Autonomous display of image/plot/figure

2008-07-15 Thread James K. Gruetzner
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On Tuesday 15 July 2008 07:48:45 John Hunter wrote:
 On Tue, Jul 15, 2008 at 8:39 AM, James K. Gruetzner [EMAIL PROTECTED] 
wrote:
  -BEGIN PGP SIGNED MESSAGE-
  Hash: SHA1
 
  On Monday 14 July 2008 21:22:31 you wrote:
   I would think that the gtk mainloop would terminate when the window
   closes (which termination should propagate back up the stack), but
   apparently that doesn't happen.
  
   I'm not sure I'm following you at the moment.  Are you calling show()
   once and closing the figure doesn't cause it to return?   or are you
   trying to call show() multiple times from a single script and
   subsequent calls to show() fail to return?
  
   Hi, Ryan,
  
   Thanks for your continued help.
  
   I am calling show() once, and closing the figure doesn't cause it to
   return? I've verified the lack of return using debug 
   sys.stderr.write() statements, as well as by following  show()  with a
   sys.exit() command.
 
  (Getting this back on the full list...)
 
  This sounds like a bug to me, specific to your set up.  I just ran a
  script (for my own sanity) and closing the figure, resulted in the
  script exiting and returning to the command prompt.  Do you happen to
  have a small complete example that replicates your problems that you
  could post here?
 
  Also, what are your versions of matplotlib and PyGtk (you are using
  GtkAgg, right)? Also, what OS are you running?
 
  Devs, what do you think?
 
  Ryan
  --
  Ryan May
  Graduate Research Assistant
  School of Meteorology
  University of Oklahoma
 
  Thanks, Ryan,  The requested info is below.
  Thanks again.

 I am not seeing any problems on the 91 branch or the 98 trunk.  Below
 is my command and output (the shell returns when I close the window
 with a click)

 [EMAIL PROTECTED]:svn python ~/test.py --verbose-helpful -dGTKAgg
 $HOME=/home/titan/johnh
 CONFIGDIR=/home/titan/johnh/.matplotlib
 matplotlib data path
 /home/titan/johnh/dev/lib/python2.4/site-packages/matplotlib/mpl-data
 loaded rc file /home/titan/johnh/.matplotlib/matplotlibrc
 matplotlib version 0.91.4
 verbose.level helpful
 interactive is False
 units is False
 platform is sunos5
 numerix numpy 1.2.0.dev5410
 Using fontManager instance from
 /home/titan/johnh/.matplotlib/fontManager.cache backend GTKAgg version
 2.6.0
 [EMAIL PROTECTED]:svn

Hi, John,

Here's my equivalent:

$ python ./test.py --verbose-helpful -dGTKAgg
$HOME=/home/jkgruet
CONFIGDIR=/home/jkgruet/.matplotlib
matplotlib data path /usr/lib/python2.5/site-packages/matplotlib/mpl-data
loaded rc file /home/jkgruet/.matplotlib/matplotlibrc
matplotlib version 0.91.2
verbose.level helpful
interactive is True
units is False
platform is linux2
numerix numpy 1.1.0
Using fontManager instance from /home/jkgruet/.matplotlib/fontManager.cache
backend GTKAgg version 2.12.0
Begun.  

  . . . at which point it hangs, even after the window is closed.  

I see that I have a older matplotlib and numpy versions.  Those are the same 
versions as in Fedora 9, so upgrading there won't help.  

OTOH, my GTKAgg version is 2.12,0, not 2.6.0.   I'm fairly sure that is where 
the problem lies, or, more likely, in GTK itself, where I have installed:

gtk+.i3861:1.2.10-59.fc8
gtk2.i3862.12.8-2.fc8

This is verified by testing several backends:
  GTKAgg:   fails to return when X is clicked
  GTK:  fails to return when X is clicked
  GTKCairo: fails to return when X is clicked
  WxAgg:displays and returns immediately (no need to click any X !!! )
  QtAgg:returns when X is clicked; 
  TkAgg:returns when X is clicked; 
  FltkAgg:  ImportError:  No module named fltk, although fltk is installed
  WX:   NotImplementedError from .../matplotlib/image.py in draw:  
renderer.draw_Image(...)
  
So . . . for my purposes, I think I'll just use QtAgg or TkAgg.

I'm not sure how I would file a bug report against GTK, however, or even *if* 
I should file one given my utter ignorance of gtk.   

I appreciate all the help shown on the list.  Y'all're very kind.  

   James
  

-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.7 (GNU/Linux)

iD8DBQFIfMa9xOXthSHeGJIRApqIAKDi1q+EA7feFvhyhWWlhyUvU0GpugCg3Kx3
+mqZBXBgGVUgtP3Fwr4+POg=
=qkT7
-END PGP SIGNATURE-


-
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK  win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100url=/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Fwd: Re: Autonomous display of image/plot/figure

2008-07-15 Thread John Hunter
On Tue, Jul 15, 2008 at 10:48 AM, James K. Gruetzner [EMAIL PROTECTED] wrote:

 OTOH, my GTKAgg version is 2.12,0, not 2.6.0.   I'm fairly sure that is where
 the problem lies, or, more likely, in GTK itself, where I have installed:

I just tested on gtk 2.12.0 and did not see the problem with mpl 0.98
and backend gtkagg.  Not sure why you are having these problems...

JDH

-
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK  win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100url=/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Fwd: Re: Autonomous display of image/plot/figure

2008-07-14 Thread Ryan May
 I would think that the gtk mainloop would terminate when the window
 closes (which termination should propagate back up the stack), but
 apparently that doesn't happen.
 I'm not sure I'm following you at the moment.  Are you calling show()
 once and closing the figure doesn't cause it to return?   or are you
 trying to call show() multiple times from a single script and subsequent
 calls to show() fail to return?
 
 Hi, Ryan,
 
 Thanks for your continued help.
 
 I am calling show() once, and closing the figure doesn't cause it to return?  
 I've verified the lack of return using debug  sys.stderr.write() statements, 
 as well as by following  show()  with a sys.exit() command.
 
(Getting this back on the full list...)

This sounds like a bug to me, specific to your set up.  I just ran a 
script (for my own sanity) and closing the figure, resulted in the 
script exiting and returning to the command prompt.  Do you happen to 
have a small complete example that replicates your problems that you 
could post here?

Also, what are your versions of matplotlib and PyGtk (you are using 
GtkAgg, right)? Also, what OS are you running?

Devs, what do you think?

Ryan

-- 
Ryan May
Graduate Research Assistant
School of Meteorology
University of Oklahoma

-
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK  win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100url=/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Fwd: Re: Autonomous display of image/plot/figure

2008-07-12 Thread Ryan May
James K. Gruetzner wrote:
 I don't really need any live interaction or a live data display; I just want 
 the thang to stop running (i.e., the process to terminate) when the figure 
 window is closed.  
 
 Unfortunately, the 
   dynamic_image_gtkagg.py
 example has the same problem.  It's final line is show().  When run as a 
 background process, everything displays well --- but when the window is 
 closed (click on X), the process fails to terminate.   So . . . the root 
 cause is that show() does not return when the shown image is closed.  
 
 If you *need* it to wait for user interaction before continuing, there might
 be a little bit more work, but I don't think it'd be much.  You could
 probably instead look at some of the Matplotlib UI widgets, like in the
 buttons.py example.
 
 I really don't need user interaction per se,  I may have to go that route an 
 establish some sort of close window and exit event.  Hmmm:  another 
 learning opportunity . . . .  :-)  
 
 The show() function is defined in
 .../matplotlib/backends/backend_gtk.py
 and looks to be calling gtk.main(), which, according to 
.../gtk-2.0/gtk/__init__.py
 appears to be deprecated in favor of mainloop().
 
 And that's as far as I can go in this:  I'm not graphics whiz, and, in fact, 
 having reached somewhat beyond my skill level,  can't even figure out how to 
 trace the mainloop call back further.  
 
 I would think that the gtk mainloop would terminate when the window closes 
 (which termination should propagate back up the stack), but apparently that 
 doesn't happen.

I'm not sure I'm following you at the moment.  Are you calling show() 
once and closing the figure doesn't cause it to return?   or are you 
trying to call show() multiple times from a single script and subsequent 
calls to show() fail to return?

Ryan

-- 
Ryan May
Graduate Research Assistant
School of Meteorology
University of Oklahoma

-
Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW!
Studies have shown that voting for your favorite open source project,
along with a healthy diet, reduces your potential for chronic lameness
and boredom. Vote Now at http://www.sourceforge.net/community/cca08
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Fwd: Re: Autonomous display of image/plot/figure

2008-07-12 Thread John Hunter
On Fri, Jul 11, 2008 at 11:55 AM, James K. Gruetzner [EMAIL PROTECTED] wrote:

 And that's as far as I can go in this:  I'm not graphics whiz, and, in fact,
 having reached somewhat beyond my skill level,  can't even figure out how to
 trace the mainloop call back further.

To make sure I capture all the events that can close the window, I
usually connect to the delete-event and the destroy-event.  Eg::

  win.connect(delete_event, gtk.mainquit)
  win.connect(destroy_event, gtk.mainquit)

where win is your gtk window.

JDH

-
Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW!
Studies have shown that voting for your favorite open source project,
along with a healthy diet, reduces your potential for chronic lameness
and boredom. Vote Now at http://www.sourceforge.net/community/cca08
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Fwd: Re: Autonomous display of image/plot/figure

2008-07-11 Thread James K. Gruetzner
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On Thursday 10 July 2008 18:50:12 you wrote:
 James K. Gruetzner wrote:
   I'm running Fedora 8, python 2.5.1, and matplotlib 0.91.2-1.fc8  from
  the yum repository.   Backend is set to GTKAgg in my matplotlibrc file.
 
  (On this list top-posting is frowned upon -- it makes the conversation
  difficult to follow.)
 
  I understand.  Sorry.  Each list is different:  I'm new here, and will
  try remember.

 No problem.  Also, don't forget reply-to-all, so that the whole of the
 list can chime in here. :)

Arrrgh  Almost all my other lists have that as default, so I'm out of the 
habit of checking.

  Your analysis is correct, the call to show() activates the GUI mainloop
  and does not return until the window is closed.  Within ipython there is
  some magic that occurs that runs the mainloop in a separate thread.
  What do you need to do after the call to show()?

  In my current situation, I need to extract and display data (images)
  independently from several different files as part of debugging a larger
  application.  (I'm really not reading a file into the original array, but
  running some shell commands using os.popen2(...) to eventually populate
  the array:  that part works.)The upshot is that in the course of a
  few hours, I may have to display (and kill) a large number of images.

  The current hang means that I have an effective memory leak, and I'd
  have to keep track of Process IDs and manually kill them every so often. 
  Were the pylab.show() command to return after closing the window
  (clicking on the X), then a backgrounded or daemon process should
  terminate.  But it doesn't. This seems to be the same problem causing
  Dragan S.'s problem.

  I'm not sure if this is a bug or a feature, but would assuredly like to
  find a way to kill the leak.

 I'm not sure about the lack of returning after the call show(), though
 it does sound like a bug.  What I *do* know is that multiple calls to
 show() is frowned upon (if not just completely unsupported).  What you
 probably want to look at is the dynamic_image_gtkagg.py example (in the
 examples/ directory).  Since you're already using GtkAgg, it should be
 *really* easy to adapt the example to fit your needs.  I've personally
 adapted it to do a live data display of a simulation run.  

I don't really need any live interaction or a live data display; I just want 
the thang to stop running (i.e., the process to terminate) when the figure 
window is closed.  

Unfortunately, the 
  dynamic_image_gtkagg.py
example has the same problem.  It's final line is show().  When run as a 
background process, everything displays well --- but when the window is 
closed (click on X), the process fails to terminate.   So . . . the root 
cause is that show() does not return when the shown image is closed.  

 If you *need* it to wait for user interaction before continuing, there might
 be a little bit more work, but I don't think it'd be much.  You could
 probably instead look at some of the Matplotlib UI widgets, like in the
 buttons.py example.

I really don't need user interaction per se,  I may have to go that route an 
establish some sort of close window and exit event.  Hmmm:  another 
learning opportunity . . . .  :-)  

The show() function is defined in
.../matplotlib/backends/backend_gtk.py
and looks to be calling gtk.main(), which, according to 
   .../gtk-2.0/gtk/__init__.py
appears to be deprecated in favor of mainloop().

And that's as far as I can go in this:  I'm not graphics whiz, and, in fact, 
having reached somewhat beyond my skill level,  can't even figure out how to 
trace the mainloop call back further.  

I would think that the gtk mainloop would terminate when the window closes 
(which termination should propagate back up the stack), but apparently that 
doesn't happen.

 Ryan

 --
 Ryan May
 Graduate Research Assistant
 School of Meteorology
 University of Oklahoma

Thanks again for your help thus far.

   James

-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.7 (GNU/Linux)

iD8DBQFId5ChxOXthSHeGJIRAqj4AKDG8RGxoQYl5va2olVUV2WQ1zjyOQCeImlr
AT+d5Fl2FuF9yWxLaJWbjEg=
=wZPg
-END PGP SIGNATURE-


-
Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW!
Studies have shown that voting for your favorite open source project,
along with a healthy diet, reduces your potential for chronic lameness
and boredom. Vote Now at http://www.sourceforge.net/community/cca08
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Fwd: Re: Autonomous display of image/plot/figure

2008-07-10 Thread Ryan May
James K. Gruetzner wrote:
  I'm running Fedora 8, python 2.5.1, and matplotlib 0.91.2-1.fc8  from
 the yum repository.   Backend is set to GTKAgg in my matplotlibrc file.
 (On this list top-posting is frowned upon -- it makes the conversation
 difficult to follow.)
 
 I understand.  Sorry.  Each list is different:  I'm new here, and will try 
 remember.  

No problem.  Also, don't forget reply-to-all, so that the whole of the 
list can chime in here. :)

 Your analysis is correct, the call to show() activates the GUI mainloop
 and does not return until the window is closed.  Within ipython there is
 some magic that occurs that runs the mainloop in a separate thread.
 What do you need to do after the call to show()?
 
 In my current situation, I need to extract and display data (images) 
 independently from several different files as part of debugging a larger 
 application.  (I'm really not reading a file into the original array, but 
 running some shell commands using os.popen2(...) to eventually populate the 
 array:  that part works.)The upshot is that in the course of a few hours, 
 I may have to display (and kill) a large number of images.  
 
 The current hang means that I have an effective memory leak, and I'd have 
 to 
 keep track of Process IDs and manually kill them every so often.  Were the 
 pylab.show() command to return after closing the window (clicking on the X), 
 then a backgrounded or daemon process should terminate.  But it doesn't.  
 This seems to be the same problem causing Dragan S.'s problem.  
 
 I'm not sure if this is a bug or a feature, but would assuredly like to find 
 a 
 way to kill the leak.
 

I'm not sure about the lack of returning after the call show(), though 
it does sound like a bug.  What I *do* know is that multiple calls to 
show() is frowned upon (if not just completely unsupported).  What you 
probably want to look at is the dynamic_image_gtkagg.py example (in the 
examples/ directory).  Since you're already using GtkAgg, it should be 
*really* easy to adapt the example to fit your needs.  I've personally 
adapted it to do a live data display of a simulation run.  If you *need* 
it to wait for user interaction before continuing, there might be a 
little bit more work, but I don't think it'd be much.  You could 
probably instead look at some of the Matplotlib UI widgets, like in the 
buttons.py example.

Ryan

-- 
Ryan May
Graduate Research Assistant
School of Meteorology
University of Oklahoma

-
Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW!
Studies have shown that voting for your favorite open source project,
along with a healthy diet, reduces your potential for chronic lameness
and boredom. Vote Now at http://www.sourceforge.net/community/cca08
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] Fwd: Re: Autonomous display of image/plot/figure

2008-07-09 Thread James K. Gruetzner
Thanks for the suggestion, Michael.   Reading it led to a bit of a forehead
slap.

Unfortunately, that didn't work either.  Curiously, it appears that
the show() command does not return.

- CODE SECTION -
#!/usr/local/bin/python

import os,sys
import pylab

def main():
  x = pylab.linspace(-10,10,100)
  y = pylab.sin(x)
  pylab.plot(x,y)
  sys.stderr.write(Begun.)
  pylab.show()
  sys.stderr.write(Done.)

if __name__ == __main__:
  main()
 END CODE -

When executed from the command line:
$ ./test.py 
   . . . the plot displays; clicking on the X closes it, but the process keeps
on running.

When executed as an argument to python:
$ python test.py 
 . . . the same behavior (except it's a python process which hangs).

The two sys.stderr.write() statements are for debugging.  The first one
executes; the second does not.  My conclusion is that the show() command does
not return.

--
When I operate interactively,
  the command pylab.plot(x,y) opens a widow labeled Figure 1.
 . . . then . . .
  the command show() writes the plot to that window (i.e., sine plot).

Clicking the X in the figure window causes the window to disappear, but
the show() command fails to return.

--

So . . . I figure that the lack of show() returning is the root problem.

Any suggestions?

 I'm running Fedora 8, python 2.5.1, and matplotlib 0.91.2-1.fc8  from the yum
repository.   Backend is set to GTKAgg in my matplotlibrc file.

  James

---

On Monday 07 July 2008 17:29:16 you wrote:
 Why do you want to fork the process?  If you just run it in the
 background it should have the desired effect:

 begin tst.py
 from pylab import *
 x = linspace(-10,10,100) # or load data from a file.
 y = sin(x)
 plot(x,y)
 show()
 end tst.py

 $ python tst.py

 Process remains in background running until the user closes the plot
 window, at which point it terminates.

 Michael.

 On 7 Jul 2008, at 2:30 PM, James K. Gruetzner wrote:
  -BEGIN PGP SIGNED MESSAGE-
  Hash: SHA1
 
  I'm not sure if this is the right venue for this question.  I've
  searched the
  archives, but without success so far.  If this is covered there (or
  elsewhere
  on the web), I'd apprciate a pointer to it so it doesn't duplicate
  bandwidth
  here.
 
  Anyway, what I'd like to do is have a python script which reads
  data from a
  file, displays an image/plot/whatever made from the data, and then
  exits,
  keeping the image displayed.
 
  I'm running Fedora 8, python 2.5.1, and matplotlib 0.91.2-1.fc8
  from the yum
  repository.   Backend is set to GTKAgg in my matplotlibrc file.
 
  My initial attempt used the double fork method from the python
  cookbook:
 
  - -Code follows--
if __name__ == __main__:
 
#From Python Cookbook
try:
  pid = os.fork()
  if pid  0:
# Exit first parent
sys.exit(0)
except OSError, e:
  print sys.stderr, fork #1 failed: %d (%s) %(e.errno,
  e.strerror)
  sys.exit(1)
 
# Decouple from parent environment
#os.chdir(/)
os.setsid()
os.umask(0)
 
# Do second fork
try:
  pid = os.fork()
  if pid  0:
# Exit from second parent; print eventual PID before exiting
print Image PID %d % pid
sys.exit(0)
except OSError, e:
  print sys.stderr, fork #2 failed:  %d (%s)%(e.errno,
  e.strerror)
  sys.exit(1)
 
# Start the main loop to display image
main()
 
  - --END CODE--
 
  The main() function reads the values appropriately into the
  variable myarr,
  and then calls imshow and show:
 
  -  Code follows ---
 
 
pylab.imshow(myarr)
pylab.show()
  - --END CODE--
 
  . . . and then exits.
 
  All works well until I try to kill the figure/image  by clicking on
  the X in
  the upper-right corner.   It disappears alright, but the process
  remains
  running, and I have to manually kill it with the kill -SIGTERM
  pid command.
 
  I'd like the process to die when I close the window.
 
  I'm really an application programmer, not a system programmer, and
  usually
  don't delve this deeply into process management, so I'm probably doing
  something extremely ignorant.  Help is appreciated.
 
  Thanks!
 
James
 
 


---


-
Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW!
Studies have shown that voting for your favorite open source project,
along with a healthy diet, reduces your potential for chronic lameness
and boredom. Vote Now at http://www.sourceforge.net/community/cca08
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Fwd: Re: Autonomous display of image/plot/figure

2008-07-09 Thread Ryan May
James K. Gruetzner wrote:
 Thanks for the suggestion, Michael.   Reading it led to a bit of a forehead
 slap.
 
 Unfortunately, that didn't work either.  Curiously, it appears that
 the show() command does not return.
 
 - CODE SECTION -
 #!/usr/local/bin/python
 
 import os,sys
 import pylab
 
 def main():
   x = pylab.linspace(-10,10,100)
   y = pylab.sin(x)
   pylab.plot(x,y)
   sys.stderr.write(Begun.)
   pylab.show()
   sys.stderr.write(Done.)
 
 if __name__ == __main__:
   main()
  END CODE -
 
 When executed from the command line:
 $ ./test.py 
. . . the plot displays; clicking on the X closes it, but the process keeps
 on running.
 
 When executed as an argument to python:
 $ python test.py 
  . . . the same behavior (except it's a python process which hangs).
 
 The two sys.stderr.write() statements are for debugging.  The first one
 executes; the second does not.  My conclusion is that the show() command does
 not return.
 
 --
 When I operate interactively,
   the command pylab.plot(x,y) opens a widow labeled Figure 1.
  . . . then . . .
   the command show() writes the plot to that window (i.e., sine plot).
 
 Clicking the X in the figure window causes the window to disappear, but
 the show() command fails to return.
 
 --
 
 So . . . I figure that the lack of show() returning is the root problem.
 
 Any suggestions?
 
  I'm running Fedora 8, python 2.5.1, and matplotlib 0.91.2-1.fc8  from the yum
 repository.   Backend is set to GTKAgg in my matplotlibrc file.
 
(On this list top-posting is frowned upon -- it makes the conversation 
difficult to follow.)

Your analysis is correct, the call to show() activates the GUI mainloop 
and does not return until the window is closed.  Within ipython there is 
some magic that occurs that runs the mainloop in a separate thread. 
What do you need to do after the call to show()?

Ryan

-- 
Ryan May
Graduate Research Assistant
School of Meteorology
University of Oklahoma

-
Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW!
Studies have shown that voting for your favorite open source project,
along with a healthy diet, reduces your potential for chronic lameness
and boredom. Vote Now at http://www.sourceforge.net/community/cca08
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users