Restrict panning and zoom limits over multiple axes

8 Ansichten (letzte 30 Tage)
Shreedhar Savant Todkar
Shreedhar Savant Todkar am 12 Mai 2021
Bearbeitet: Adam Danz am 17 Mai 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 Kommentar
Jonas
Jonas am 12 Mai 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

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Adam Danz
Adam Danz am 12 Mai 2021
Bearbeitet: Adam Danz am 17 Mai 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