4.90909

4.9 | 11 ratings Rate this file 94 Downloads (last 30 days) File Size: 15.88 KB File ID: #26007
image thumbnail

On-figure magnifier

by David Fernandez-Prim

 

02 Dec 2009 (Updated 28 Mar 2010)

Powerful on-figure magnifier, suitable for the publication of compact graphical results

Editor's Notes:

This file was selected as MATLAB Central Pick of the Week

| Watch this File

File Information
Description

This utility provides a powerful zooming tool specially designed for the documentation of original and zoomed 2D graphics of images on the same plot.

It is composed of two blocks (the secondary axes and the magnifier). The secondary axes, which can be arbitrarily allocated within the limits of the figure, displays the area marked by the magnifier.

The highly versatile interface of the 'on-figure magnifier' offers a world of possibilities in a broad range of applications and fields. The Keyboard/mouse or programmatic configuration of this tool allows the user to set her or his own graphic style, to suit the requirements of any publication's editor. More details on interfacing and properties can be found in the .m file.

EXAMPLE: (for usage examples, run 'magnifyOnFigure_examples.m')
         
PROPERTIES:
       'secondaryAxesFaceColor': ColorSpec
       'edgeWidth' Color of the box surrounding the secondary
                    axes, magnifier and link. Default 1
       'edgeColor': Color of the box surrounding the secondary
                    axes, magnifier and link. Default 'black'
       'displayLinkStyle': Style of the link. 'none', 'straight' or
                    'edges', with 'straight' as default.
       'mode': 'manual' or 'interactive' (allowing
                    adjustments through mouse/keyboard). Default
                    'interactive'.
       'units' Units in which the position vectors are
                    given. Only 'pixels' currently supported
       'initialPositionSecondaryAxes': Initial position vector ([left bottom width height])
                    of secondary axes, in pixels
       'initialPositionMagnifier': Initial position vector ([left bottom width height])
                    of magnifier, in pixels
       'secondaryAxesXLim': Initial XLim value of the secondary axes
       'secondaryAxesYLim': Initial YLim value of the secondary axes

HOT KEYS (active if 'mode' set to 'interactive')

 -In a figure with multiple magnigier instances
       'Tab': Switch the focus from one magnifier instance
                    to the next one on the current figure.
       'Mouse pointer on secondary axes or magnifier of a tool+double left click'
                    Regain focus

 -On the focused magnifier instance
       'up arrow': Moves magnifier 1 pixel upwards
       'down arrow': Moves magnifier 1 pixel downwards
       'left arrow': Moves magnifier 1 pixel to the left
       'right arrow': Moves magnifier 1 pixel to the right
       'Shift+up arrow': Expands magnifier 10% on the Y-axis
       'Shift+down arrow': Compress magnifier 10% on the -axis
       'Shift+left arrow': Compress magnifier 10% on the X-axis
       'Shift+right arrow': Expands magnifier 10% on the X-axis
       'Control+up arrow': Moves secondary axes 1 pixel upwards
       'Control+down arrow': Moves secondary axes 1 pixel downwards
       'Control+left arrow': Moves secondary axes 1 pixel to the left
       'Control+right arrow': Moves secondary axes 1 pixel to the right
       'Alt+up arrow': Expands secondary axes 10% on the Y-axis
       'Alt+down arrow': Compress secondary axes 10% on the Y-axis
       'Alt+left arrow': Compress secondary axes 10% on the X-axis
       'Alt+right arrow': Expands secondary axes 10% on the X-axis
       'PageUp': Increase additional zooming factor on X-axis
       'PageDown': Decrease additional zooming factor on X-axis
       'Shift+PageUp': Increase additional zooming factor on Y-axis
       'Shift+PageDown': Decrease additional zooming factor on Y-axis
       'Control+Q': Resets the additional zooming factors to 0
       'Control+A': Displays position of secondary axes and
                    magnifier in the command window
       'Control+D': Deletes the focused tool
       'Mouse pointer on magnifier+left click' Drag magnifier to any
                    direction
       'Mouse pointer on secondary axes+left click' Drag secondary axes in any
                    direction

Acknowledgements

The author wishes to acknowledge the following in the creation of this submission:
ZoomBox, magnify, magnifyrecttofig, Jeweler's Loupe

MATLAB release MATLAB 7.4 (R2007a)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (20)
18 Dec 2009 Kris Gryte

Very nice work. A few things:

(i) Hack: in order to delete the magnifier, secondary axes, and link, I simply added a new keyboard shortcut (alt+C), and then directed to a sub-function which deleted the desired axes handles and restored the figure and main axes default settings.

(ii) Problem: I have noticed the following correlation. When the figure window is small, say, 10 in x 8 in, the magnification, motion, and shortcuts work wonderfully. This changes, however, when I expand the figure window so it is maximized (i.e., roughly, 24 in by 11 in). Each time I attempt to used the magnification function on the expanded figure window, my Matlab session crashes, and if this system is able to remain responsive, I receive repetitive warnings that I have exceeded by 'listener recursion limit'. This issue is not alleviated when I reset the recursion limit to something extreme (e.g., from 500 to 10000). Hence, something within the configuration, perhaps the 'buttonmotionfcn' or some other callback which continuously updates/has eventdata, seems to find the increased window size rather disagreeable.

This stated, I was curious if you have a possible workaround for issue (ii).

(iii) Generalization: a nice, albeit more complicated, addition would be the ability to incorporate more than one plot inset for a given axes and/or figure. Possibly, by including another shortcut command, one could cycle between making a given secondary axes/magnifier active and inactive. For example, store all axes within a figure, and then upon the shortcut command, provide a 'listdlg' to allow the user to choose which axes to make active (which may or may not be a magnifier). If a magnifier axes is selected, then make the associated handles active, et cetera.

The function has outstanding functionality and use, and I am eager to have it fully and smoothly incorporated in my GUI. Thank you for this submission.

-Kris

10 Jan 2010 Kris Gryte

Thank you for addressing the issues reported earlier. The various bug fixes, additional support, and increased functionality are greatly appreciated.

Perhaps a further generality might be the following:

- Multiple insets across multiple subplots within the same figure. I have addressed this by including another shortcut which activates the next (or previous) axes.

Thanks again.

-Kris

11 Jan 2010 David Fernandez-Prim

Kris, thanks a lot to you too for your comments. In version 1.16, you could already switch from one inset to the next one in a figure( by pressing 'tab' of doble-clicking the inset to focus), regardless they are on the same axes or not.
Maybe this feature could already suit your needs.

I'm currently working on the performance issue, which is not an easy one. I'll let you know the status. Please don't hesitate to report any other issue/bug you might find.

- David

09 Feb 2010 Kris Gryte

David:

Thank you for the response. Regarding switching from one inset to another, indeed, 'tab' does activate the next inset, regardless of the axes; however, the situation I envision is having say, three insets on one subplot, two insets on another subplot, three insets on yet a third subplot--for whatever reason and despite aesthetics. Maybe now the problem becomes evident. If, say, I am on the third subplot and the 8th inset, in order to access the 7th inset, I have either to (i) cycle through the other 7 insets, or (ii) use my mouse to double-click. I, personally, like shortcuts and avoid using my mouse (habit), thus, I find it more convenient to cluster my insets by axis and, for the active axes, I cycle between my 'local' insets. Further, depending on the order of placing insets on whatever axes, two insets on an axes may not be next to each other in the 'tab' order. Third, a shortcut for activating axes allows for placing insets, not necessarily even activating insets, on different axes, without mouse-clicks. And finally, I usually do most things GUI-based, in which I provide tags for each axes/inset and then provide dialogs (e.g., listboxes, etc) to allow the user to select specific axes and/or insets for manipulation. But, of course, this is my preference.

As for other notes:

(i) I like shortcuts, but, for other users, they love their mouse. Hence, an easy extension is simply to provide a 'uicontextmenu' for each created axes, in which the menu, say, for the 'magnifier' provides the various shortcuts/commands particular to that axes (resize, magnification, etc), and similarly for the inset. A user may then right-click an inset and simply select to resize or expand or whatever. And further, by listing 'Increase X-Mag (alt++)', or whatever the shortcut is, the user has a reference to remind his/herself of the various shortcuts.

(ii) Another extension may be the ability to synchronize two insets. For example, suppose I have two subplots and one inset per subplot. Further, the two subplots contain related information, and I would like to magnify a single region in both subplots. In this implementation, I have to individually drag each magnifier to the desired region separately, and then manually attempt to align the two axes. This may, or may not, be easy depending on the length of the displayed data and the resolution of the axes. A nice extension would be (yet another shortcut!) to link two insets together, such that they move in step. A similar concept has been implemented by 'Dual Cursors', which may be found on the Central File Exchange. Or, another possibility is two insets on the same axes, but separated by a given spacer. If I link them, then when I move one axis to the left by 10 units, the second axis also moves to the left exactly 10 units. Similarly for magnification, resizing, et cetera. Hence, having the ability to apply shortcuts/operations to more than one inset at a time, accomplished either using 'loops' or the 'set' function. Of course, if performance was already an issue, this suggestion would only compound matters.

Thanks again for the fixes and comments. Great work.

-Kris

04 Apr 2010 ben harper

First of all, Thank you for your great work :)

After plotting the magnifier, if we are in interactive mode, we can change the size of magnifier and secondary axes.

Is it possible to add a key to script, when we press it it would show "final PositionSecondaryAxes" and "final PositionMagnifier"?

04 Apr 2010 David Fernandez-Prim

Dear Ben,

The functionality you request is already available in the tool.

In interactive mode, if you hit 'control + A', you will get information about the current position of secondary axes and magnifier on the command window of MATLAB.

After that, you only need to set the properties 'PositionSecondaryAxes' and 'PositionMagnifier' to the given values on the next call to this function.

I hope this answers your request :)

01 Jun 2010 J. Caspar

While this looks like a nice tool, I experienced problems with it due to its method of use of the figure's userdata field. It appears that the tool ignores the possibility that another application might already be using the userdata and hence when it encounters unexpected data in the field it crashes. I've always tried to treat userdata as shared space - when I read it I assume that there might be data there that I did not put there and I alway try to leave existing data unchanged when I resave to userdata. This would be a useful upgrade for this script.

04 Jun 2010 theoxarhs alex

Everything is great, except for the fact than when semilogy is used instead of plot, the zoom box is not placed correctly on the graph. Is is misplaced a little bit lower than it should be.

Any changes to overcome this problem?
Please feel free to mail me at theoxarhs at google.com if a simple change could resolve this bug(?).
Thanks in advance.

13 Jul 2010 Corey Kelly

This is great! Two simple questions:
1. If I wanted to change the color of the borders of the magnifier and the secondary axis, where in the code would I make the change? As is, they're showing as black, and my images are predominantly black, making them difficult to see.
2. I'm integrating the magnifier as part of a GUI, and would like to be able to toggle it on and off. It's not clear to me how to remove the magnifier once it has been initialized. Is it possible to create a handle when the magnifier starts, which can be used as an argument to a delete() call?

14 Jul 2010 David Fernandez-Prim

Hi Corey,

1. You can easily change the color of the border of the magnifier and secondary axis through the property 'edgeColor', which by default is set to black.

2. At this moment, the tool does not provide a handle at calling time. However, there are several supported Hot Key combinations that might be useful for your purpose. 'Control+D', for instance, can be used to delete the tool from the current figure.

I hope that helps!

Regards

22 Sep 2010 suraj

Cheers to the great work. I have a couple of questions to ask. i) How do I set the Y limits of the magnifier to match the plot area height? ii) Can I use the magnifier as a push button callback in a GUI? Thanks in advance.
Suraj

23 Feb 2011 Royi Avital

This is Amazing!

I wish you added support for more units (The axis units would be great).

22 Mar 2011 ben harper

hello,
i'm sorry if this feature is already added but i couldn't see.

how can i magnify on subplots?
i added between the subplots but it couldn't work.
thank you.

figure
subplot(2,1,1)
...
subplot(2,1,2)
...
magnifyonfigure
...
subplot(2,1,3)
...

16 Apr 2011 mythili

hi..great work.....
its very useful..
thank u...

04 May 2011 Xuan  
05 May 2011 Jose Ercolino

Very nice work.

13 Sep 2011 Pieter van den Berg  
10 Nov 2011 Tian Pan

good

09 Feb 2012 Merc Shahraki

Thanks alot
its very useful

12 Apr 2012 Amin

how I can enlarge and display in a window Figure

Please login to add a comment or rating.
Updates
03 Dec 2009

Solved bug when 'displayLinkStyle' is set to 'edges'

04 Dec 2009

Added possibility to select target axes in a multiaxes figure

06 Dec 2009

Solved bug appearing when any of the axes are reversed. It also works on images now.

07 Dec 2009

Cosmetic changes

08 Dec 2009

Solved bug when axis mode is set to other than 'normal'.
Besides, added 'frozenZoomAspectRatio' zoom mode, useful when working with images.

08 Dec 2009

Solved bug when the contents of the target axes are other than 'line' or 'image'

07 Jan 2010

Added 'delete' functionality.
Added support to multiple instances of the tool on the same axes.
Solved several minor bugs

07 Jan 2010

Solved bug when resizing the host figure

07 Jan 2010

Improved help documentation

28 Mar 2010

Tool identification feature added. Now, 'Control+I' shows/hides the tool identifier (red background color when the tool has the focus, black otherwise)

Tag Activity for this File
Tag Applied By Date/Time
axis David Fernandez-Prim 02 Dec 2009 14:36:43
zoom in David Fernandez-Prim 02 Dec 2009 14:36:44
axes David Fernandez-Prim 02 Dec 2009 14:36:44
magnify David Fernandez-Prim 02 Dec 2009 14:36:44
plot David Fernandez-Prim 02 Dec 2009 14:36:44
magnifier David Fernandez-Prim 02 Dec 2009 14:36:44
overview David Fernandez-Prim 02 Dec 2009 14:36:44
magnifying glass David Fernandez-Prim 02 Dec 2009 14:36:44
data exploration David Fernandez-Prim 02 Dec 2009 14:36:44
zoom David Fernandez-Prim 02 Dec 2009 14:36:44
graphics David Fernandez-Prim 02 Dec 2009 14:36:44
rectangle David Fernandez-Prim 02 Dec 2009 14:36:44
publishing David Fernandez-Prim 02 Dec 2009 14:36:44
publish David Fernandez-Prim 02 Dec 2009 14:36:44
self_rating Matt Fig 05 Dec 2009 17:12:27
potw Shari Freedman 25 Mar 2010 13:32:29
pick of the week Jiro Doke 11 Feb 2011 20:07:27
axes Jose Ercolino 05 May 2011 12:03:55
graphics Jose Ercolino 05 May 2011 12:03:56
axis Jose Ercolino 05 May 2011 12:03:59
plot Jose Ercolino 05 May 2011 12:04:15
magnifier Jose Ercolino 05 May 2011 12:04:25
magnify Jose Ercolino 05 May 2011 12:04:29
zoom Jose Ercolino 05 May 2011 12:04:33
publishing Jose Ercolino 05 May 2011 12:04:42

Contact us at files@mathworks.com