Restrict panning and zoom limits over multiple axes

7 次查看(过去 30 天)
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