If anyone faces a similar issue, there is a solution here.
http://scipy.org/Cookbook/Matplotlib/Interactive_Plotting
Essentially, we should also check for "toolbar.mode"
Thanks,
Venkat.
Venkat Ramanan wrote:
> Hi,
>
> I have written a simple image viewing tool with window/level controls
> linked to the right mouse, which generally works okay.
>
> But when I use the pan/zoom button, clicking and dragging the right
> mouse button changes the zoom as intended, but also affects the
> window/level too which is undesirable.
>
> How to change the callback so that the pan/zoom mode doesn't affect
> window/level?
>
> The code is attached.
>
> If there are better image viewing tools using matplotlib, I can
> upgrade, but I couldn't find them on a quick search. The goal is to
> add some plotting capability ( plot row, col on user-specified
> coordinates) and some ROI drawing capability. ( See my other post for
> those questions. )
>
> Matplotlib: 0.87.7, python: 2.5 ubuntu 7.04
>
> Thanks,
> Venkat.
>
> ------------------------------------------------------------------------
>
> #!/usr/bin/env python
> import scipy
> import pylab
> from pylab import cos, sqrt, arctan2, sqrt,pi,cm, clim,
> get_current_fig_manager
> import sys
> # Displaying an image with window/level controls
> # from matplotlib
>
> pylab.ion()
>
> xstart = 0;
> ystart = 0;
> win = 0;
> lev = 0;
> vmax_orig = 0;
> vmin_orig = 0;
>
> def on_click(event):
> #get the x and y coords, flip y from top to bottom
> global win,lev
> win = im.norm.vmax - im.norm.vmin;
> lev = (im.norm.vmax + im.norm.vmin)/2;
> x, y = event.x, event.y;
> if event.button==3:
> if event.inaxes is not None:
> global xstart,ystart
> xstart = event.xdata;
> ystart = event.ydata;
> #print 'click:data coords', event.xdata, event.ydata;
>
> def on_move(event):
> #get the x and y pixel coords
> x, y = event.x, event.y
> scale = 10;
> if event.button==3:
> if event.inaxes is not None:
> xdelta = event.xdata - xstart;
> ydelta = event.ydata - ystart;
> xratio = xdelta / (im.get_extent()[1]-im.get_extent()[0]);
> yratio = ydelta / (im.get_extent()[3]-im.get_extent()[2]);
>
> new_win = xratio*scale + win;
> new_lev = yratio*scale + lev;
> if new_win < 0: new_win = 0;
>
> clim_high = new_lev + new_win/2;
> clim_low = new_lev - new_win/2;
> clim(clim_low,clim_high);
>
> #print 'move:deltas', xdelta, ydelta
> #print 'clim_low: ', clim_low, 'clim_high: ', clim_high
>
> def on_release(event):
> global win,lev
> x, y = event.x, event.y
> if event.button==2:
> if event.inaxes is not None:
> clim(vmin_orig,vmax_orig);
> print 'release: vmin: ',im.norm.vmin,'vmax: ',im.norm.vmax
>
> def viewimage(imdata):
> global im,vmax_orig,vmin_orig
> im=pylab.imshow(imdata,origin='lower',cmap=cm.gray);
> vmax_orig = im.norm.vmax;
> vmin_orig = im.norm.vmin;
> binding_id = pylab.connect('motion_notify_event', on_move)
> pylab.connect('button_press_event', on_click)
> pylab.connect('button_release_event', on_release)
> pylab.show();
>
> def main():
> # Creating the grid of coordinates x,y
> x,y = scipy.ogrid[-1.:1.:.01, -1.:1.:.01]
> z = 3*y*(3*x**2-y**2)/4 + .5*cos(6*pi * sqrt(x**2 +y**2) + arctan2(x,y))
> viewimage(z);
>
> if __name__ == '__main__':
> main()
>
> ------------------------------------------------------------------------
>
> -------------------------------------------------------------------------
> SF.Net email is sponsored by:
> Check out the new SourceForge.net Marketplace.
> It's the best place to buy or sell services for
> just about anything Open Source.
> http://sourceforge.net/services/buy/index.php
> ------------------------------------------------------------------------
>
> _______________________________________________
> Matplotlib-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
-------------------------------------------------------------------------
SF.Net email is sponsored by:
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users