View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from

4.9 | 54 ratings Rate this file 106 Downloads (last 30 days) File Size: 4.13 KB File ID: #5961 Version: 1.0
image thumbnail



Rick Hindman (view profile)

  • 1 file
  • 4.88462


30 Sep 2004 (Updated )

Turns the mouse into a pop-up magnifying glass to look at details of 2D plots.

Editor's Notes:

This file was a File Exchange Pick of the Week

| Watch this File

File Information

Ever wish MATLAB had a magnifying glass so you could look at the details of a small region of your plots without having to zoom in and out again and again? Just run 'magnify.m' with the figure of interest as the current figure, then use the left mouse button to bring up a magnified veiw that you control. Or use the 'Ctrl' key while clicking to bring up a magnifying glass that 'locks' onto the figure when released (for use when copying and printing figures). Use the '<' and '>' keys to make the magnifying glass smaller or larger. Use '-' and '+' to decrease or increase the magnification level.


This file inspired Magnifyrecttofig, Shiftline, and On Figure Magnifier.

MATLAB release MATLAB 7.0.1 (R14SP1)
MATLAB Search Path
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (68)
28 Feb 2017 chunyang lee

Thank you!

Comment only
21 Feb 2017 QIANG XIAO


14 Jan 2017 Mojgan Rostaminia

21 Dec 2016 xiaping

Thank you very much!

Comment only
20 Dec 2016 mms3airei

19 Dec 2016 jack

jack (view profile)

It is really help me a lot.

05 Dec 2016 nhan hanh

Thank you !!!
It helps me a lot, and I make a little changes in my code if you don't mind.
Thank you !

15 Nov 2016 FATCAT

FATCAT (view profile)

Thank you

Comment only
10 Nov 2016 li yu

li yu (view profile)

28 Oct 2016 Harish Babu Kankanala

15 Sep 2016 Nicolai Neumann

31 Aug 2016 amrkzp

amrkzp (view profile)

14 Aug 2016 hehe

hehe (view profile)

really good~

16 Jun 2016 pengxin han

Very helpfull

Comment only
02 Jun 2016 Ma Kang

Great job! It helps me a lot, and I make a little changes in my code.

plot(1:100,randn(1,100),(1:300)/3,rand(1,300)), grid on,
% You must complete the amplification in the figure before you run the next code.Assuming we just magnify once.
d(1).Position=[0 0.5 d(1).Position(3) d(1).Position(4)];%Move the magnified figure to the specific position
axis = d(2);
rectangle('Position',[d(1).XLim(1),d(1).YLim(1),d(1).XLim(2)-d(1).XLim(1),d(1).YLim(2)-d(1).YLim(1)],'LineWidth',2,'LineStyle','--','EdgeColor','r')%Mark the magnified part in the original figure

12 May 2016 Carl Witthoft

Should replace "fullcrosshair" with "crosshair" because the former is unsupported in R2015 and later (possibly also in R2014)

20 Nov 2015 Pengli Zhou

That's very helpful! Good work! the matlab is more powerful now

07 Jul 2015 Fernando Esteves

18 Jan 2015 joseph

joseph (view profile)

06 Jun 2014 Michael

It doesn't seem to work when the figure style is docked - any ideas why not?

To reproduce the behavior, try the following which doesn't work:
grid on;magnify
But if you go back to set(0,'DefaultFigureWindowStyle','normal'); then it works just fine.

Comment only
23 May 2014 Fengming

Thank you very much!

13 May 2014 dong

dong (view profile)

thanks man! It's very brilliant!

03 Jan 2014 Amr Hamza

Awesome !!

17 Sep 2013 Ali

Ali (view profile)

It was very usefull for my thesis, thank you. Great job!

08 Mar 2013 Sean Archer


28 Feb 2012 Xiangchun

Nice work.
How to detach it from the current figure without closing it?


Comment only
27 Jan 2012 Martin Fuchs

19 Jun 2011 Nilimb

Nilimb (view profile)

excellent code. how do i extend this to an image inside uipanel on figure ?

06 Jun 2011 François

25 Jun 2010 Victor P

Excellent! Thanks!

24 Apr 2010 Yuval Cohen


Comment only
24 Apr 2010 Yuval Cohen

06 Apr 2010 Yao

Yao (view profile)

great job^_^

in my case, the y axis is log scaled, seems just a littile modification as follows will do

set(a2,'YLim',a1_cp(2)+(1/a2_param(1))*(a2_pos(4)/a1_pos(4))*diff(get(a1,'YLim'))*[-0.5 0.5]) (in function "ButtonMotionCallback")
set(a2,'YLim',10.^(log10(a1_cp(2))+(1/a2_param(1))*(a2_pos(4)/a1_pos(4))*log10(Ylima1(2)/Ylima1(1))*[-0.5 0.5]))

29 Dec 2009 Evgeny Pr

Evgeny Pr (view profile)

I made the following changes to work properly:

in ==> magnify>ButtonDownCallback at 39
- set(get(a2,'Children'), ...
- 'LineWidth', 2);

+ line_obj = findobj(a2, 'Type', 'line');
+ if ~isempty(line_obj)
+ set(line_obj, 'LineWidth', 2);
+ end

Comment only
29 Dec 2009 Evgeny Pr

Evgeny Pr (view profile)

Very good function! But there is a slight problem. By operation with the image in function there is an error:

>> imshow(im, []);
>> magnify;
??? Error using ==> set
There is no 'LineWidth' property in the 'image' class.

Error in ==> magnify>ButtonDownCallback at 39
set(get(a2,'Children'), ...

Thus after an error function continues to work normally at mouse moving.
I think, it is necessary to check that the object on axes is the image and to eliminate in that case change of properties of a line.

15 Oct 2009 ted p teng

ted p teng (view profile)

28 Sep 2009 Bahram

Bahram (view profile)

Excellent job. I guess it needs another revision to take care of some of the bugs that reveal themselves in the newer version of Matlab.

I use this function with imshow() and it gives me an error that:

There is no 'LineWidth' property in the 'image' class.
Error in ==> magnify>ButtonDownCallback at 39
set(get(a2,'Children'), ...

Of course I could easily solve it by removing that line of code. Also the Ctrl key seems to leave the box on the image. Another thing that one might want to change is to set the XTick and YTick of the second axis to [ ]:

set(a2, 'XTick', [ ], 'YTick', [ ]);

Again, excellent job!

10 Jul 2009 qooroo

qooroo (view profile)

great app, but it deletes one set of data when I use it to look at plotyy graphs. a point for consideration?


Comment only
03 Jul 2009 Todd Welti

I also like it, BUT doesn't seem to work well when the x axis is log based. This is pretty much all I use (frequency is normally plotted this way). I looked at the code but not sure how long it would take me to make that mod.....

Comment only
24 May 2009 mohamed Elmorsy

Excellent,Wonderful Function

Comment only
23 Mar 2009 Akshay B

Neat!! Thanks a lot!

19 Mar 2009 Lissa

Lissa (view profile)

10 Mar 2009 Lissa

Lissa (view profile)

25 Feb 2009 Dharma

Dharma (view profile)

This is really awesome.
I am not sure if I am doing it wrong, ctrl+click makes the box stay on fig., how can I remove it if wanted to plot another figure on same axes.

Comment only
15 Jan 2009 Martin

Martin (view profile)

This looks extremely useful, anyone seen any problems with it on later versions of MATLAB R2007a? The zoom area is not located over the plot so cannot be seen...

Comment only
02 Jan 2009 Husam Aldahiyat

Superb, etc.

06 Dec 2007 Jim Fallon

Excellent instruction for handling mouse button motion and using 'UserData' in a GUI. Beside learning, it saved hours for development of my own GUI.

J. Fallon

24 Mar 2007 Sami Murad

good it is really helpfull

16 Mar 2007 Hyway Yin

Very nice!

26 Jul 2006 Dinesh Appya


22 Jun 2006 Gordon Dix

Very useful code. Great work!

05 Jun 2006 Yvgeny Shvarzman

If anybody can tell me if I can use this code too magnify other programs (for examle power point details) ?

Comment only
05 Jun 2006 Gadget Gadget

31 Mar 2006 Meche Nova

I've solved this problem by setting up Units to "normalized". Works fine with several axes within one gui. Question:
how to delete a leftover window if you
occasionally hit the right mouse button?

14 Mar 2006 Daphne W

This is an excellent tool! Thanks!
For those who needed it to work with images just comment out the line with LineWidth:
% set(get(a2,'Children'),...
% 'LineWidth', 2);
That solves the problem.

What I am trying to figure out now, is how to make it work inside a gui with several axes. Seems to put the magnified image at the edge of the gui for some reason. Any ideas?

14 Mar 2006 Lee Jay Fingersh

Very nice app, thank you! I modified the controls slightly. Now, the arrow keys control magnification in each axis separately while the brackets control both together and the +/- keys control window size.

09 Mar 2006 Shanrong Zhang

Great job! MATLAB should add it as a standard icon in their figure panel...

One small comment: if you could add one sentence "figure(f1);" after the first sentence "if (nargin == 0), f1 = gcf; end;", it should be more convenient. By doing this, the figure that is selected by user or the current one would automatically pop up to be "magnified".

Thanks for sharing !!!

03 Mar 2006 Brett Shoelson

I echo Jiro's suggestion, as well as the group consensus that this is a very nice function!

02 Mar 2006 Jiro Doke

Very nice! One comment:

If you could put a check before you set the LINEWIDTH, in case there are objects that doesn't have that property (e.g. image, lighting, etc). I can use this to magnify image files.

02 Mar 2006 Marcelø Zeri

Very good!

25 Feb 2006 John D'Errico

On a scale of 1 to 5, I'll put this at 6.

11 Nov 2005 Vicky Svidenko

Wow! Excellent!

28 Sep 2005 Christina Hebert

Very cool

07 May 2005 Tsakani Lotten


30 Jan 2005 Kang Dong-il

You made what I REALLY needed.. thank you

29 Oct 2004 James Goodwin

very very good!

07 Oct 2004 Fahad Al Mahmood

Wonderful Function Indeed! Congratulations!

05 Oct 2004 Alex Podgaetsky


11 May 2016 1.0

BSD License

Contact us