Restrict panning and zoom limits over multiple axes

4 views (last 30 days)
Shreedhar Savant Todkar
Shreedhar Savant Todkar on 12 May 2021
Edited: Adam Danz on 17 May 2021
For one of my apps, I have two axes (app.axes1 and app.axes2). The axes1 is a 2D image (traced using imagesc()) and axes2 is a 1D vector plot indicating some sort of labels. In both axes, the zoom and pan actions will be done in only X-axis.
What I would like to do is automatically zoom axes2 (with the same specs) when axes1 is zoomed and vice-versa. And the same in case of panning as well. To do so over multiple axes, the command linkaxes proved to be useful. However, I am looking for something can we limit the panning to a certain boundary (something like xlim or ylim) ?
For example, my image has a boundary limits of 0 - 150 (x-axis) and 0 - 4096 (y-axis). But the panning and zoom commands go beyond these values as well.
Is there a way to control this using some sort of limits?
version: MATLAB 2021a AppDesigner
  1 Comment
Jonas
Jonas on 12 May 2021
you could write a function which checks the limits continuously and sets it to your specified maximum if the limits get bigger than you want

Sign in to comment.

Answers (1)

Adam Danz
Adam Danz on 12 May 2021
Edited: Adam Danz on 17 May 2021
You can assign a listener that responds to changes to xlim|ylim in one pair of axes and updates the other pair of axes while maintaining axis aspect ratios. If you're using Matlab R2021a or later, you can use the LimitsChangedFcn instead of a listener which is the better approach.
The demo in this answer shows how to achieve this using two axes that are on top of each other but the process will be no different for axes that are not overlapping.
The only thing you'll do differently, I presume, is to apply the listener or LimitsChangedFcn to both axes instead of just one of them.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by