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.
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.
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.
Works great! Thanks.
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
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');
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.
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).
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:
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.
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.
added colorbar support, supersedes previous update
Greatly improved. In addition to growing plots, we now can grow images. Also, figure legends are preserved.
Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.