Have you ever wanted to zoom in on one axes and have another axes zoom in at the same time? Have you ever wanted to zoom in only on the x-axis but not the y-axis? If so, please watch this minute and a half video to see how.
Hi,yes linkaxes(h,’xy’) is useful when you want to zoom in/out subplots together.but the disadvantage is that axes being linked have to have the same xy limits,how do u zoom both if your axes don’t have the same limits? i tried linkprop,but do not work.
If you want to link axes but not lock them exactly together, you can do that with the set and get commands to set the xlim and ylim properties of the axes. This is likely done with callbacks too.
If you have an older version of MATLAB (before this function was introduced) you can get much the same effect by using SET, GET, and callbacks that will change the xlim and ylim properties of the other axes.
Not as easy, but it can be made to work. It might just be better to get the newest version of MATLAB.
Hi Doug,
I know this is a long time after the post, but am hoping you will still get to this.
I would like to link a few axes and have them zoom in togetehr, however the problem is that these axes are each plotted separately.
I have 3 axes in a GUI. Each one is a step in an image processing procedure that I am running. I would like to be able to zoom in on the 1st axes, then plot the second and have the zoom remain (same for when I add the 3dd plot). I have been able to do this for the first time, but then if I replot always returns to full size.
Help?
When you do the plot again, MATLAB may be creating a new axes that replaces the original. Some plot routines do this quietly. You need to set up the xlim, ylim, and linkaxes again when this happens. Depending on the kind of plot you are doing, it might be better to do a LINE, rather than a PLOT. This is more surgical, and changes less of the props in the axes and such.
Hi Doug,
If only life were so simple. My “plots” are actually images from a microscope, which I pre-process in the gui to determine filter parameters etc. I use imagesc to show them.
I have tried setting the xlim, ylim to the zoomed value, but didn’t quite work. Will try again to find the right place to redefine.
I had the same problem with trying to link images. The problem arises from the fact that the handle returned from image scale is not an axis and linkaxes’ error checking throws an exception. I checked the parent, and it is an axis. Linking the two parent axes gives the correct behavior:
% Link two images
% get(h, ‘Parent’) returns the axes associated
% with the images. I don’t think this is documented
% behavior, so it is probably subject to breakage, and
% really should be moved into a supported function
% such as linkprop/linkaxes with the appropriate function.
% As get(h, ‘Parent’) returns a cell array, we need to
% convert it to a matrix.
linkaxes(cell2mat(get(h, ‘Parent’)), ‘xy’);
Doug, I don’t know enough about when Matlab replaces axes to know whether this will survive Daphne’s replot…
Hi,yes linkaxes(h,’xy’) is useful when you want to zoom in/out subplots together.but the disadvantage is that axes being linked have to have the same xy limits,how do u zoom both if your axes don’t have the same limits? i tried linkprop,but do not work.
If you want to link axes but not lock them exactly together, you can do that with the set and get commands to set the xlim and ylim properties of the axes. This is likely done with callbacks too.
Doug
How can I implement the linkaxes function within Matlab 6? Thanks
If you have an older version of MATLAB (before this function was introduced) you can get much the same effect by using SET, GET, and callbacks that will change the xlim and ylim properties of the other axes.
Not as easy, but it can be made to work. It might just be better to get the newest version of MATLAB.
Doug
Hi Doug,
I know this is a long time after the post, but am hoping you will still get to this.
I would like to link a few axes and have them zoom in togetehr, however the problem is that these axes are each plotted separately.
I have 3 axes in a GUI. Each one is a step in an image processing procedure that I am running. I would like to be able to zoom in on the 1st axes, then plot the second and have the zoom remain (same for when I add the 3dd plot). I have been able to do this for the first time, but then if I replot always returns to full size.
Help?
Thanks,
Daphne
Daphne,
When you do the plot again, MATLAB may be creating a new axes that replaces the original. Some plot routines do this quietly. You need to set up the xlim, ylim, and linkaxes again when this happens. Depending on the kind of plot you are doing, it might be better to do a LINE, rather than a PLOT. This is more surgical, and changes less of the props in the axes and such.
Doug
Hi Doug,
If only life were so simple. My “plots” are actually images from a microscope, which I pre-process in the gui to determine filter parameters etc. I use imagesc to show them.
I have tried setting the xlim, ylim to the zoomed value, but didn’t quite work. Will try again to find the right place to redefine.
Thanks for the input,
Daphne
Dear Daphne and Doug,
I had the same problem with trying to link images. The problem arises from the fact that the handle returned from image scale is not an axis and linkaxes’ error checking throws an exception. I checked the parent, and it is an axis. Linking the two parent axes gives the correct behavior:
% Link two images
% get(h, ‘Parent’) returns the axes associated
% with the images. I don’t think this is documented
% behavior, so it is probably subject to breakage, and
% really should be moved into a supported function
% such as linkprop/linkaxes with the appropriate function.
% As get(h, ‘Parent’) returns a cell array, we need to
% convert it to a matrix.
linkaxes(cell2mat(get(h, ‘Parent’)), ‘xy’);
Doug, I don’t know enough about when Matlab replaces axes to know whether this will survive Daphne’s replot…
Best wishes,
Marie
what I did to link three separate axes on a GUI where each axis will display a different image.
Insert this into the main (OpeningFcn) of the GUI app.
set(gcf, ‘CurrentAxes’, handles.sampleAxis);
ax(1) = gca;
set(gcf, ‘CurrentAxes’, handles.sampleAxis2);
ax(2) = gca;
set(gcf, ‘CurrentAxes’, handles.sampleAxis3);
ax(3) = gca;
linkaxes(ax, ‘xy’);
Obv handles.sampleAxis etc are the names of the axes.
Worked like a charm, cheers all.
Charlie,
This works, but there is an easier way:
ax = [handles.sampleAxis ;
handles.sampleAxis2;
handles.sampleAxis3]
Simpler is almost always better.
-Doug
hi there,
i would like to know how to display a zoomed image in matlab please? ^^
something like:
I = imread(‘image.jpg’)
:%zoom image 2x
imshow(zoomed image)
@sieker,
Programatically, you could set the xlim and ylim properties.
Doug
If you need to constrain the zoom or pan programatically then have a look at the “zoom” and “pan” functions.