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 Center および File ExchangeData Exploration についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by