Skip to Main Content Skip to Search
File Exchange
MATLAB Newsgroup
Link Exchange
  Blogs  
 Contest 
MathWorks.com

Doug’s Pick of the Week

November 27th, 2006

Linked zoom and constrained zoom in MATLAB

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.

8 Responses to “Linked zoom and constrained zoom in MATLAB”

  1. Andrew.H replied on :

    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.

  2. Doug Hull replied on :

    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

  3. Peter Moses replied on :

    How can I implement the linkaxes function within Matlab 6? Thanks

  4. Doug replied on :

    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

  5. Daphne replied on :

    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

  6. Doug replied on :

    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

  7. Daphne replied on :

    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

  8. Marie replied on :

    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

Leave a Reply


Doug Hull is an Application Engineer at The MathWorks. A MATLAB user since 1994, he gets paid to live, eat, and breathe MATLAB! This blog is dedicated to promoting the File Exchange by highlighting files and original video content.



  • Moran: Hi Chris, I tried everything I could think of, and have sent several observations about this bug to support,...
  • odessit: Hello, I have compiled standalone application with deploytool. It would work fine, but the error is in...
  • Duane Hanselman: FYI… % strmatch replacements % strmatch is obsolete, strncmp and strcmp are built in % case...
  • Doug: Duane, I just looked, I did not see an m-lint warning against STRMATCH in 2008a. However, I seem to recall what...
  • hashem: Hi Doug, I built a GUI and write a help for it in “chm” (compiled HTML file) format, and I...
  • Tim Davis: I left out the comments in the code, above. Most of the functions should be familiar to most MATLAB users....
  • Tim Davis: I was a little confused by all the back-and-forth discussion of zero blocks. Is a block of zeros to be...
  • Tim Davis: Try this one. It doesn’t require any toolboxes, just “sparse” and “dmperm” ....
  • Duane Hanselman: Did anyone ever try replacing strmatch with strcmp (or its siblings as needed)? I recall mlint...
  • jiro: @Daniel, We do use the hardware, but we don’t expose the supersampling feature through that path, so if...

These postings are the author's and don't necessarily represent the opinions of The MathWorks.

Related Topics