View License

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

» Watch video

Highlights from

4.5 | 6 ratings Rate this file 7 Downloads (last 30 days) File Size: 3.42 KB File ID: #7867 Version: 1.7
image thumbnail



Matt Caywood (view profile)


17 Jun 2005 (Updated )

With one click, zoom axes for better visibility.

Editor's Notes:

This file was selected as MATLAB Central Pick of the Week

| Watch this File

File Information

What if you have a number of tiny subplots or images in a figure window and would like to be able to visually inspect them?

Call allowaxestogrow(f) on a figure f with any number of sub-axes.

Then, whenever one of the plots or images is clicked, it immediately grows to the size of the full window (or a pre-set size).

When clicked again, it returns to its original position.

MATLAB release MATLAB 7.7 (R2008b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (12)
11 Sep 2012 Sebastian Hölz

It should be mentioned that the code does not work for plots with log-axes. This is because it is using the OpenGL renderer.


Comment only
27 Jun 2010 GERMÁN

you could place the code example. I have a error when running the program.

Comment only
13 Nov 2009 Matt Caywood

Matt Caywood (view profile)

Bass, this is designed to replace the built-in figure zoom/pan tools, which I found slow and inadequate.

I believe the reason it doesn't work with them is that we overlay the original plot with an invisible patch that reliably traps mouse clicks. So you're zooming & panning the invisible patch, not the plot.

If instead you attach the togglesubplot event handler to the original plot, you can use it with the zoom/pan controls -- but then the grow/shrink control won't be very reliable.

Comment only
14 Oct 2009 Yuri K

Yuri K (view profile)

Works great! Thanks.

03 Jun 2009 Bass

Bass (view profile)

Nice tool.
Unfortunately, if you try and use the zoom/pan tools after applying allowaxestogrow to your figure they don't work NOR does allowaxestogrow zoom functionality

01 May 2009 Jackson Shen

26 Feb 2009 Jonas

Jonas (view profile)

Very neat piece of code!

I use it to allow a user to select ROIs on images in subplots. To make sure that the axes aspect ratio is preserved (otherwise, the ROI looks much different on zooming), I modified line 56 the following way (maybe you should also copy DataAspectRatioMode):

iax = axes('Position',get(ax,'Position'), 'PlotBoxAspectRatioMode',get(ax,'PlotBoxAspectRatioMode'), 'NextPlot','add');

24 Feb 2009 Matt Caywood

Matt Caywood (view profile)

Eindhoven, this program already does allow axes to be zoomed in and out.

It relies on Matlab being able to trap clicks on certain features of the plot. Sometimes when a plot is very complex and axes are large, clicks do not register as readily as they do when the axis is small.

Try clicking on different objects in the plot, or reordering the objects in the plot. Or, you can add "set(obj,'ButtonDownFcn',@shrinksubplot);" to different objects obj in the plot to make them triggers for zooming out.

Comment only
26 Oct 2007 Eindhoven de Gekste

One thing that should be implemented, is the possibility to return to the original subplots figure, after zooming in on a magnified subplot (to me that seems impossible at the moment).

Comment only
26 Oct 2007 Eindhoven de Gekste

Exactly does what I needed, very easy to implement

04 Jun 2007 T W

Re new version issued 1/6/07 ...
On a page of line subplots, I also have an axes that has the following characteristics:
ans =
This axes causes allowaxestogrow to crash on:
if (strcmp(get(chax,'Type'),'image') || strcmp(get(chax,'Type'),'line'))
with the error ...
??? Operands to the || and && operators must be convertible to logical scalar values.

Comment only
22 Jun 2005 Steve Dunn

Useful scripts. Thanks.

01 Jun 2007

Greatly improved. In addition to growing plots, we now can grow images. Also, figure legends are preserved.

04 Jun 2007

added colorbar support, supersedes previous update

25 Feb 2009 1.4

Allows user to set predefined size for zoomed plot; colorbars finally work well.
Much simplified by using invisible patches to trap clicks. Now requires Matlab's OpenGL renderer which may cause side effects on some older systems.

29 Apr 2009 1.5

Try to preserve plot order better; Preserve plot aspect ratio. (Version 0.31)

08 May 2009 1.6

Work around Matlab bug in which figure plots are created in.

15 May 2009 1.7

Increased compatibility with others' graphics scripts by using appdata, single button-down function.

Contact us