going through a lot of plots
![](https://secure.gravatar.com/avatar/b684c02bab6c8d54c0c25c4b69ee1135.jpg?s=120&d=mm&r=g)
I wonder if anyone has a good pattern they'd like to share for how to page through a lot of plots (mayavi.mlab or matplotlib or Chaco or whatever). I find myself in this situation a lot: I'm looking at a sequence of plots, one for each piece of data in a collection. I usually find myself writing a loop with a plot command followed by raw_input()so that I hit enter in the terminal window IPython session to move to the next item. I usually make this conditional so that I can process in batch without looking at the plots if I choose. This has the effect of producing a newline in the terminal every time I want to move on to the next plot, which is far from ideal, especially in the situation where I'm not printing anything else in that window. I figure there probably is a general way of solving this problem satisfactorily that I just haven't thought of, but any toolkit- specific ideas would be appreciated too. I'd rather avoid mucking with event-handlers since it would force control flow to depend on the plotting toolkit, removing the ability to just "turn off" plot-n-wait. Any thoughts? David
![](https://secure.gravatar.com/avatar/764323a14e554c97ab74177e0bce51d4.jpg?s=120&d=mm&r=g)
On Wed, May 13, 2009 at 17:56, David Warde-Farley <dwf@cs.toronto.edu> wrote:
I wonder if anyone has a good pattern they'd like to share for how to page through a lot of plots (mayavi.mlab or matplotlib or Chaco or whatever).
I find myself in this situation a lot: I'm looking at a sequence of plots, one for each piece of data in a collection. I usually find myself writing a loop with a plot command followed by raw_input()so that I hit enter in the terminal window IPython session to move to the next item. I usually make this conditional so that I can process in batch without looking at the plots if I choose.
This has the effect of producing a newline in the terminal every time I want to move on to the next plot, which is far from ideal, especially in the situation where I'm not printing anything else in that window.
I figure there probably is a general way of solving this problem satisfactorily that I just haven't thought of, but any toolkit- specific ideas would be appreciated too. I'd rather avoid mucking with event-handlers since it would force control flow to depend on the plotting toolkit, removing the ability to just "turn off" plot-n-wait.
I usually write up a quick Traits UI that embeds the Chaco Plot with a slider or whatever to select the dataset. This lets me move forwards and backwards and abort in the middle much more naturally. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco
![](https://secure.gravatar.com/avatar/afdaaab755ef79ac9e1374882d60ae9f.jpg?s=120&d=mm&r=g)
I find myself in this situation a lot: I'm looking at a sequence of plots, one for each piece of data in a collection. I usually find myself writing a loop with a plot command followed by raw_input()so that I hit enter in the terminal window IPython session to move to the next item. I usually make this conditional so that I can process in batch without looking at the plots if I choose.
This has the effect of producing a newline in the terminal every time I want to move on to the next plot, which is far from ideal, especially in the situation where I'm not printing anything else in that window.
Old-school alternative is to put the TTY into cbreak (aka "rare" mode, between "raw" and "cooked"), and capture a single key-hit. (Except that ^C still breaks, which is handy.) For windows, the C runtime has a similar getkey function. Here's windows / posix code for that that I've assembled from various snippets online; note that the latter uses the well-known decorator module. I've also included an "iskeydown" function which I find useful in various situations... Zach import os if os.name == 'nt': import msvcrt def getkey(): c = msvcrt.getch() if c == '\x00' or c == '\xE0': #functions keys msvcrt.getch() return c def iskeydown(): return msvcrt.kbhit() elif os.name == 'posix': import tty, sys, select import decorator @decorator def _in_cbreak(func, *args, **kws): fd = sys.stdin.fileno() old = tty.tcgetattr(fd) tty.setcbreak(fd, tty.TCSANOW) try: return func(*args, **kws) finally: tty.tcsetattr(fd, tty.TCSAFLUSH, old) @_in_cbreak def getkey(): return sys.stdin.read(1) @_in_cbreak def iskeydown(): if select.select([sys.stdin], [], [], 0) == ([sys.stdin], [], []): return sys.stdin.read(1) else: return False
![](https://secure.gravatar.com/avatar/573ed3088eea742af8bcfeac90bc882d.jpg?s=120&d=mm&r=g)
Zachary Pincus wrote:
I find myself in this situation a lot: I'm looking at a sequence of plots, one for each piece of data in a collection. I usually find myself writing a loop with a plot command followed by raw_input()so that I hit enter in the terminal window IPython session to move to the next item. I usually make this conditional so that I can process in batch without looking at the plots if I choose.
This has the effect of producing a newline in the terminal every time I want to move on to the next plot, which is far from ideal, especially in the situation where I'm not printing anything else in that window.
Old-school alternative is to put the TTY into cbreak (aka "rare" mode, between "raw" and "cooked"), and capture a single key-hit. (Except that ^C still breaks, which is handy.) For windows, the C runtime has a similar getkey function.
Here's windows / posix code for that that I've assembled from various snippets online; note that the latter uses the well-known decorator module. I've also included an "iskeydown" function which I find useful in various situations...
I have collected some useful snippets to do a similar thing too - now I merged the functionality, added some sugar (pause functions), stirred and cooked - see the attachment. $ python getch.py Are you ok with me using it in my (BSD) project? thanks, r.
![](https://secure.gravatar.com/avatar/afdaaab755ef79ac9e1374882d60ae9f.jpg?s=120&d=mm&r=g)
I have collected some useful snippets to do a similar thing too - now I merged the functionality, added some sugar (pause functions), stirred and cooked - see the attachment.
Are you ok with me using it in my (BSD) project?
Feel free to use it for anything!
![](https://secure.gravatar.com/avatar/39916bae984cb93b797efd2b175f59c0.jpg?s=120&d=mm&r=g)
On 5/14/2009 6:46 AM Zachary Pincus apparently wrote:
Feel free to use it for anything!
Just a reminder that these days it is much safer to be explicit. E.g., "I release this code into the public domain" or "I release this code under the 3 clause BSD license." Alan Isaac
![](https://secure.gravatar.com/avatar/afdaaab755ef79ac9e1374882d60ae9f.jpg?s=120&d=mm&r=g)
On 5/14/2009 6:46 AM Zachary Pincus apparently wrote:
Feel free to use it for anything!
Just a reminder that these days it is much safer to be explicit. E.g., "I release this code into the public domain" or "I release this code under the 3 clause BSD license."
Thanks Alan. I release that code into the public domain. Question, though: safer for whom? I presume it's safer for the person using the code... are there any considerations for the original author of the code, though? Zach
![](https://secure.gravatar.com/avatar/39916bae984cb93b797efd2b175f59c0.jpg?s=120&d=mm&r=g)
On 5/14/2009 11:34 AM Zachary Pincus apparently wrote:
Question, though: safer for whom? I presume it's safer for the person using the code... are there any considerations for the original author of the code, though?
Only the following: the author's actual intent is more likely to be realized. Cheers, Alan
![](https://secure.gravatar.com/avatar/b684c02bab6c8d54c0c25c4b69ee1135.jpg?s=120&d=mm&r=g)
On 13-May-09, at 9:27 PM, Zachary Pincus wrote:
Old-school alternative is to put the TTY into cbreak (aka "rare" mode, between "raw" and "cooked"), and capture a single key-hit. (Except that ^C still breaks, which is handy.) For windows, the C runtime has a similar getkey function.
Here's windows / posix code for that that I've assembled from various snippets online; note that the latter uses the well-known decorator module. I've also included an "iskeydown" function which I find useful in various situations...
Awesome, thanks! David
![](https://secure.gravatar.com/avatar/5c9fb379c4e97b58960d74dcbfc5dee5.jpg?s=120&d=mm&r=g)
On Wed, May 13, 2009 at 06:18:31PM -0500, Robert Kern wrote:
I usually write up a quick Traits UI that embeds the Chaco Plot with a slider or whatever to select the dataset. This lets me move forwards and backwards and abort in the middle much more naturally.
Same thing with Mayavi's mlab (I look at 3D data). I modify in place the objects plotted, for speed. Check out https://svn.enthought.com/enthought/browser/Mayavi/trunk/examples/mayavi/int... for some hints on how to do this. Gaël
![](https://secure.gravatar.com/avatar/573ed3088eea742af8bcfeac90bc882d.jpg?s=120&d=mm&r=g)
Hi Gael, Gael Varoquaux wrote:
On Wed, May 13, 2009 at 06:18:31PM -0500, Robert Kern wrote:
I usually write up a quick Traits UI that embeds the Chaco Plot with a slider or whatever to select the dataset. This lets me move forwards and backwards and abort in the middle much more naturally.
Same thing with Mayavi's mlab (I look at 3D data).
I modify in place the objects plotted, for speed. Check out https://svn.enthought.com/enthought/browser/Mayavi/trunk/examples/mayavi/int... for some hints on how to do this.
Just to let you know that the example does not work right away with ets-3.2.0 $ ./mlab_interactive_dialog.py Traceback (most recent call last): File "./mlab_interactive_dialog.py", line 36, in <module> from enthought.mayavi.core.api import PipelineBase ImportError: No module named api It works perfectly after this small change: from enthought.mayavi.core.api import PipelineBase -> from enthought.mayavi.core.pipeline_base import PipelineBase cheers, r.
![](https://secure.gravatar.com/avatar/5c9fb379c4e97b58960d74dcbfc5dee5.jpg?s=120&d=mm&r=g)
On Thu, May 14, 2009 at 08:34:46AM +0200, Robert Cimrman wrote:
Just to let you know that the example does not work right away with ets-3.2.0
$ ./mlab_interactive_dialog.py Traceback (most recent call last): File "./mlab_interactive_dialog.py", line 36, in <module> from enthought.mayavi.core.api import PipelineBase ImportError: No module named api
It works perfectly after this small change:
from enthought.mayavi.core.api import PipelineBase -> from enthought.mayavi.core.pipeline_base import PipelineBase
Thanks for pointing this out. I should never point to examples in the trunk, but only in the tags. Pointing to examples in the trunk leads to examples not works on people's boxes... Gaël
![](https://secure.gravatar.com/avatar/b684c02bab6c8d54c0c25c4b69ee1135.jpg?s=120&d=mm&r=g)
On 13-May-09, at 7:18 PM, Robert Kern wrote:
I usually write up a quick Traits UI that embeds the Chaco Plot with a slider or whatever to select the dataset. This lets me move forwards and backwards and abort in the middle much more naturally.
Thanks for the idea. I followed Gael's tutorial example pretty closely and did the same with my existing matplotlib code (not that Chaco isn't great and all, just taking the path of least resistance at this point). This has a slight problem when running ipython with -wthread, in that if I want to view several disparate groups (i.e. I have many images, and I'm processing them one by one, so I've set it up so I can look at all the objects in an image) - there is no way (as far as I can tell) to get my function to wait on configure_traits() before moving on to the next image (I suppose I could embed another slider or something to select the image...). Is there any way to tell a GUI to take the interpreter thread hostage? David
![](https://secure.gravatar.com/avatar/39916bae984cb93b797efd2b175f59c0.jpg?s=120&d=mm&r=g)
On 5/14/2009 11:47 AM David Warde-Farley apparently wrote:
Thanks for the idea. I followed Gael's tutorial example pretty closely and did the same with my existing matplotlib code
Could you add this to the Matplotlib cookbook? http://www.scipy.org/Cookbook/Matplotlib Thanks, Alan Isaac
![](https://secure.gravatar.com/avatar/b684c02bab6c8d54c0c25c4b69ee1135.jpg?s=120&d=mm&r=g)
Done. Although that cookbook could use some serious TLC... For one thing, maybe that mplot3d stuff ought to be removed? I didn't but I made the warning explicit on the main cookbook page. David On 14-May-09, at 12:24 PM, Alan G Isaac wrote:
On 5/14/2009 11:47 AM David Warde-Farley apparently wrote:
Thanks for the idea. I followed Gael's tutorial example pretty closely and did the same with my existing matplotlib code
Could you add this to the Matplotlib cookbook? http://www.scipy.org/Cookbook/Matplotlib
Thanks, Alan Isaac
_______________________________________________ SciPy-user mailing list SciPy-user@scipy.org http://mail.scipy.org/mailman/listinfo/scipy-user
![](https://secure.gravatar.com/avatar/764323a14e554c97ab74177e0bce51d4.jpg?s=120&d=mm&r=g)
On Thu, May 14, 2009 at 10:47, David Warde-Farley <dwf@cs.toronto.edu> wrote:
On 13-May-09, at 7:18 PM, Robert Kern wrote:
I usually write up a quick Traits UI that embeds the Chaco Plot with a slider or whatever to select the dataset. This lets me move forwards and backwards and abort in the middle much more naturally.
Thanks for the idea. I followed Gael's tutorial example pretty closely and did the same with my existing matplotlib code (not that Chaco isn't great and all, just taking the path of least resistance at this point).
This has a slight problem when running ipython with -wthread, in that if I want to view several disparate groups (i.e. I have many images, and I'm processing them one by one, so I've set it up so I can look at all the objects in an image) - there is no way (as far as I can tell) to get my function to wait on configure_traits() before moving on to the next image (I suppose I could embed another slider or something to select the image...).
The latter would probably be preferable for much the same reasons as using a slider for selecting each object. But it cold be more code.
Is there any way to tell a GUI to take the interpreter thread hostage?
obj.edit_traits(kind='livemodal') -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco
participants (6)
-
Alan G Isaac
-
David Warde-Farley
-
Gael Varoquaux
-
Robert Cimrman
-
Robert Kern
-
Zachary Pincus