Hi,
I have done this with pygist (see attached snippet), but not with
matplotlib (yet) as it is a bit to slow for big datasets.
I believe it should be relatively easy to implement a similar mouse
handling loop for
matplotlib, someone else can probably fill in with a better solution.
if you use pcolormesh instead of pcolor in a similar matplotlib
implementation the performance will be reasonable.
Helge
On 9/8/06, Rob Hetland <[EMAIL PROTECTED]> wrote:
I am interested in making an 'interactive mask.' That is, I am
creating a model of estuarine flow, where the grid is rectangular,
and part of the domain will be land, not included in the simulation
through a mask. I would like to be able to modify this mask using a
tool that will allow me to click cells on and off.
I can think of a few ways to do this, but I thought I would ask y'all
first. A rough outline of the code would be:
1. pcolor the grid
2. Catch clicks in the figure, and determine which cell is clicked.
3. Toggle the masking of that cell, and re-draw the figure
Has anybody done this?
Any ideas about any of the parts? I think I can handle part 1. I'm
worried part 3 might be inefficient.
-Rob
----
Rob Hetland, Associate Professor
Dept. of Oceanography, Texas A&M University
http://pong.tamu.edu/~rob
phone: 979-458-0096, fax: 979-845-6331
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users
def edit(h, redraw=None, level=0.0, xpole=0.0, ypole=0.0, dx=4.0, dy=4.0, ylong=58.0):
"""
Click in cells to alter values:
left click in a cell to see the value of h,
middle click to modify value manually,
right click to quit the 'toggle' session.
shift + middle button give cell 'level' value
shift + right button undo last 'levelling'
Navigation:
ctrl+left click zooms in,
ctrl + right click zooms out.
ctrl + hold-middle-and-move to pan
give parameters for the polar stereographic proj to see lon,lat for point
defaults to
xpole=0.0, ypole=0.0, dx=4000.0, dy=4000.0, ylong=58.0
"""
im,jm=h.shape
undolist={}
while True:
mus=gist.mouse()
[x1,y1]=mus[0:2]
button=mus[9]
modifier=mus[10]
#print 'got button ',button,' modifier ',modifier
gi=int(x1) ; gj=int(y1)
if modifier==0:
if button==1:
# output longitude and latitude for easy comp with sea map.
[lon,lat]=gr2sph(real(x1), real(y1), \
xpole, ypole, dx, dy, ylong)
lodeg=floor(lon) ; ladeg=floor(lat)
lomin=floor((lon-lodeg)*60)
lamin=floor((lat-ladeg)*60)
print '[%i,%i] (%i,%i) lon: %i°%i` lat:%i°%i` value %fm' % \
(gi,gj,gi+1,gj+1,lodeg,lomin,ladeg,lamin,h[gi,gj])
elif button==2:
# output longitude and latitude for easy comp with sea map.
[lon,lat]=gr2sph(x1, y1, xpole, ypole, dx, dy, ylong)
lodeg=floor(lon) ; ladeg=floor(lat)
lomin=floor((lon-lodeg)*60) ;
lamin=floor((lat-ladeg)*60)
print '[%i,%i] (%i,%i) lon: %i°%i` lat:%i°%i`' % \
(gi,gj,gi+1,gj+1,lodeg,lomin,ladeg,lamin)
print "Surroundings:"
for j in range(gj+1,gj-2,-1):
for i in range(gi-1,gi+2):
if i<im and j<jm:
print h[i,j],
else:
print "Out",
print ""
h[gi,gj]=input('New value=')
if redraw:
redraw()
elif button==3:
break
elif modifier==1:
if button==2:
print "zeroing out h (currently h=",h[gi,gj],") at i,j=",gi,gj,\
" shift+right button to undo"
if undolist.has_key((gi,gj)):
undolist[(gi,gj)].append(h[gi,gj])
else:
undolist[(gi,gj)]=[h[gi,gj]]
h[gi,gj] = level
if redraw:
redraw()
if button==3:
if undolist.has_key((gi,gj)):
if len(undolist[(gi,gj)])>0:
val = undolist[(gi,gj)].pop()
print "reset value of h in pt i,j=",gi,gj," to h=",val
h[gi,gj]=val
if redraw:
redraw()
elif modifier==4:
if button==1:
# zoom in
fac=0.5
lim=gist.limits()
ofx=0.5*fac*(lim[1]-lim[0])
ofy=0.5*fac*(lim[3]-lim[2])
gist.limits( x1-ofx,x1+ofx,y1-ofx,y1+ofx)
print x1,y1,ofx,ofy
elif button==3:
# zoom out
fac=1.5
lim=gist.limits()
ofx=0.5*fac*(lim[1]-lim[0])
ofy=0.5*fac*(lim[3]-lim[2])
gist.limits( x1-ofx,x1+ofx,y1-ofy,y1+ofy)
elif button==2:
# pan
lim=gist.limits()
ofx=mus[2]-mus[0]
ofy=mus[3]-mus[1]
gist.limits( lim[0]-ofx,lim[1]-ofx,lim[2]-ofy,lim[3]-ofy)
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users