File Exchange

image thumbnail


version 1.7 (3.42 KB) by

With one click, zoom axes for better visibility.



View License

Editor's Note: This file was selected as MATLAB Central Pick of the Week

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.

Comments and Ratings (12)

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.



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

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.

Yuri K

Yuri K (view profile)

Works great! Thanks.


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

Jackson Shen


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');

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.

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).

Eindhoven de Gekste

Exactly does what I needed, very easy to implement


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.

Steve Dunn

Useful scripts. Thanks.



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


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


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


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.

added colorbar support, supersedes previous update

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

MATLAB Release
MATLAB 7.7 (R2008b)

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

» Watch video