Restrict panning and zoom limits over multiple axes

조회 수: 7 (최근 30일)
Shreedhar Savant Todkar
Shreedhar Savant Todkar 2021년 5월 12일
편집: Adam Danz 2021년 5월 17일
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
Jonas
Jonas 2021년 5월 12일
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

댓글을 달려면 로그인하십시오.

답변 (1개)

Adam Danz
Adam Danz 2021년 5월 12일
편집: Adam Danz 2021년 5월 17일
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.

카테고리

Help CenterFile Exchange에서 Data Exploration에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by