how to make matplotlib faster?

P.S.: by the way I solved the cursor problem I posted (and

    > got no answer) by defining a new cursor class (something
    > already hinted by many on the web), if anyone is
    > interested..

Been out of town at meetings for the last week...

Have you seen
http://matplotlib.sourceforge.net/examples/coords_demo.py, which shows
how to connect to mouse motion and click? The interface is being
streamlined in 0.65. Ie in CVS, one simply needs to do

  def on_click(event): pass
  connect('button_press_event', on_click)

Currently key_press_event is not implemented (though mouse move and
motion to capture and report key presses as event.key). We added this
because this is how we do the event handling across backends for the
toolbar. There are also some fixes in CVS to make disconnects work
properly, eg in the tk backend.

It would be fairly straightforward to add a key_press_event under the
same framework.

For "cursoring", see the *cursor*.py examples in the examples subdir
of the matplotlib src distro.

But please also post your solution which may be useful....

JDH

Hi,

1. slow plot
2. cursor issue
3. key press event !

···

-------
1/

Here is the piece of code which is quite slow I think. Compared to pgplot this
is a factor of more than 10. It does first draw a default plot (0,1 ?) and then
overplot on it for each subplot.

for this particular case I have 10 subplots. The slices are made of about 10-20
points each only (stored in a 3D array which is 48x5x20 points).
I hope this answers the question. Sorry for the ''specifics''.

        for i in arange(ncoef) :
           subplot(nrow, 2, i+1)
           if i > 1 :
              temparray = self.Vcoef[indgal][i][:minind] / self.Vcoef[indgal][1][:minind]
              plot(self.Vrad[indgal][:minind], temparray, 'b-o', ms=4)
           else :
              plot(self.Vrad[indgal][:minind], self.Vcoef[indgal][i][:minind], 'b-o', ms=4)
           ylabel('C\_\{%d'%i\+'\}')

        for i in arange(ncoef) :
           j = i + ncoef
           subplot(nrow, 2, j+1)
           plot(self.Vrad[indgal][:minind], self.Vphi[indgal][i][:minind], 'b-o', ms=4)
           ylabel('\\phi\_\{%d'%i\+'\}')

2/ the cursor issue and how to interact with it:
yes indeed the solution I took is close to what is shown in some examples.
I used a new class which I then use later on in interactive mode or not.
Below is a simple/shortened example of the structure I create by just transferring
the data (x,y,key, etc) to the cursor structure. I can then use : toto = cursor()
to have it working. (I in fact define several different cursor_* classes for different purposes).
So sorry if my mail sounded like ''I have found a new way...''.

class cursor :
   def __init__(self):
      print 'Class initialized'
      self.figure = Figure()
      self.canvas = get_current_fig_manager().canvas
      self.canvas.mpl_connect('button_press_event', self.on_click)
      self.x = 0
      self.y = 0
      self.button = 1

   def on_click(self, event):
      self.x = event.x
      self.y = event.y
      self.xd = event.xdata
      self.yd = event.ydata
      self.button = event.button
      ...

3/ key press event

Currently key_press_event is not implemented (though mouse move and
motion to capture and report key presses as event.key). We added this
because this is how we do the event handling across backends for the
toolbar. There are also some fixes in CVS to make disconnects work
properly, eg in the tk backend.

It would be fairly straightforward to add a key_press_event under the
same framework.

That WOULD be great since this is exactly what I needed. For example being
able to type ''h'' to make an horizontal cut of my image at the location corresponding
to the mouse position.... I do that easily with ppgplot for example.

--

Observatoire de Lyon emsellem@...419...
9 av. Charles-Andre tel: +33 4 78 86 83 84
69561 Saint-Genis Laval Cedex fax: +33 4 78 86 83 86
France http://www-obs.univ-lyon1.fr/eric.emsellem