On Wed, Sep 29, 2010 at 11:12 PM, Jonathan Slavin <jsla...@cfa.harvard.edu> wrote: > This is interesting. It seems that the event.x, event.y values are for > the entire figure area rather than limited to the image. Anyone know > how to get the image values instead?
Typically, images in matplotlib are associated with "data coordinate". And mouse events have "xdata" and "ydata" attributes. However, if you're using imshow with the "extent" keyword, you need one more step. Below is an example. arr = np.arange(10).reshape((2,5)) x1, x2, y1, y2 = [-1.5, 3.5, 2.5, 4.5] imshow(arr, extent=[x1, x2, y1, y2], origin="lower") from matplotlib.transforms import Bbox, BboxTransform bbox_in = Bbox.from_extents([x1, y1, x2, y2]) bbox_out = Bbox.from_bounds(-0.5, -0.5, arr.shape[1], arr.shape[0]) # transform from data coordinate into image coordinate. tr = BboxTransform(bbox_in, bbox_out) print tr.transform_point((-1, 3)) # pixel (0,0) of arr print tr.transform_point((3, 4)) # pixel (4,1) of arr > > Also, I wonder how one might get the values of the pixels (i.e. image > value) at the pixels that you click on. One more thing -- is there a > way to make the cursor be a full plot window cross -- graphically like: > ------------------ > | | | > | | | > | | | > |--------|---------| > | | | > | | | > ------------------ > It makes it easier to align with the axes sometimes (the IDL astronomy > library has a routine called rdplot that does this). > One option is to use "widgets" http://matplotlib.sourceforge.net/examples/widgets/cursor.html Regards, -JJ > Jon > > > ------------------------------------------------------------------------------ > Start uncovering the many advantages of virtual appliances > and start using them to simplify application deployment and > accelerate your shift to cloud computing. > http://p.sf.net/sfu/novell-sfdev2dev > _______________________________________________ > Matplotlib-users mailing list > Matplotlib-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > ------------------------------------------------------------------------------ Start uncovering the many advantages of virtual appliances and start using them to simplify application deployment and accelerate your shift to cloud computing. http://p.sf.net/sfu/novell-sfdev2dev _______________________________________________ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users