Hi, I am following this mailing list for a while now and
> considering to convert to matplotlib at some point. Whether
> this is feasable depends on the following two points:
> 1) I would like to know if there is an equivalent to the
> scipy.xplt.mouse command which (in its simplest form) waits
> for a mouse click and returns its coordinates:
> Example: #------------------------------------- from
> scipy.xplt import * x=arange(0.0,1.0,0.1) plg(x*x,x)
> m=mouse(1,-1,"click with the mouse") print "x,y=",m[0],m[1]
> #-------------------------------------
> John's reply
> http://mail.python.org/pipermail/python-list/2004-April/216550.html
> shows that it is possible to connect mouse events with
> functions. However, that code depends on the back-end and
> is not as short as the above one (though more flexible, of
> course ;-).
For some time, we've provided basic cross GUI event handling with the
canvas.connect method. Todd Miller had the idea to port the gtk
connect interface to Tk. For example, the demo coords_demo.py runs
unchanged on TkAgg and GTKAgg. This is only a partial implementation,
and in CVS I've extended it a bit more. The new method is called
mpl_connect, and you will be able to do, across GUIs, calls like
def on_move(event):
# get the x and y coords
x, y = event.x, event.y
...snip...
canvas.mpl_connect('motion_notify_event', on_move)
I plan to provide the motion notify, on click, and key press events,
and provide some extra positional information in the events, namely
canvas coordinate location and axes coordinate location. The backend
will handle things like flipy so the script can ignore it. I'm in the
process of designing a better toolbar and am using this cross-GUI
event handling to minimize the burden of implementing the toolbar in
the various backends.
In order to do something like the
m = mouse(1,-1,"click with the mouse")
print "x,y=",m[0],m[1]
example, it would be necessary to implement some cross gui blocking
capability, so that the execution of the script is halted until the
block is removed. I don't see this as a major problem, but will
require some input from people with experience on the not-GTK GUIs.
It's probably not be necessary, though, since it's only a few more
keystrokes to do
def on_click(event): print 'x, y =', event.x, event.y
canvas.mpl_connect(''button_press_event', on_click)
This should be ready by the 0.61 release. BTW, as a wx expert,
perhaps you have a code snippet I can use which calls the event
Connect and Disconnect methods directly. I'm currently trying to
figure this out for the wx implementation of mpl_connect and
mpl_disconnect.
> 2) For one set of applications I would like to be able to
> plot several times 1000 points (or more). Optimally would
> be to plot one point after another to get a dynamical
> impression. In the application I have in mind there would
> be no need to store these points (ie zooming is not
> necessary) which normally degrades performance. Presently
> for me the solution for this type of things is our
> PlottingCanvas for wxPython, see
> http://www.physik.tu-dresden.de/~baecker/python/plot.html
> and there the StandardMap.py example.
There is a lot of interest in making dynamical plotting more
efficient. Currently, the entire figure is redrawn with each frame
update, which is clearly not ideal for dynamic figures in which only a
portion needs to be redrawn. I'm interested in making some changes to
better support "real time" data acquisition, where the quotes mean
"fast enough to handle most use cases".
My current thought is to support drawing to subsections of the agg
canvas, eg, so that a single axes, line or patch could be updated
without updating the entire figure canvas. To support this, each
object would need to know it's rectangular extent (done), take a
snapshot of the background canvas before drawing (to be done) and know
how to render itself to canvas (done). In addition, agg and the
backends would need to be extended to allow drawing of subregions of
the canvas, which should be fairly easy. By calling the right
combination of store_background, draw and erase, you could get much
faster dynamic plots.
The current implementation (redrawing the entire figure) is pretty
fast on a fast machine, but needs to be faster.
How do you do this in PlottingCanvas? Do simply add objects to the
canvas and redraw the entire canvas if you need to remove an object,
or do you support selective erasing and removal of objects?
JDH