Clear Filters
Clear Filters

xlim add listener 'auto' does not work

2 views (last 30 days)
Daniel Lemus
Daniel Lemus on 7 May 2020
Edited: Adam Danz on 15 Apr 2021
Hi
I am using 2019b and have not been able to successfully use an evenlistener on the XLim of my axes. I want to listen to changes on the size of the axes but it seems it does not work when the XLimMode = 'auto' altough there is a clear change in XLim. Looking abit more on the issue I found a workaround (https://nl.mathworks.com/matlabcentral/answers/369377-xlim-listener-for-zoom-reset-and-linkaxes-strange-behavior) which I presume does not work anymore in this release.
addlistener(parent_ax,'XLim','PostSet',@ReposFootPrint); % This only works when XLimMode = 'manual'
This alternative using a manual property does not work given that the propety is not SetObservable
addlistener(struct(parent_ax).XAxis,'Limits','PostSet' ,@ReposFootPrint);
Any ideas on how can I use the listener in 'auto' mode?
Thank you
  4 Comments
Daniel Lemus
Daniel Lemus on 7 May 2020
Edited: Daniel Lemus on 7 May 2020
Fig 1. Original Placement of footprint @(1,1)
Fig 2. After ploting a new line
plot(parent_ax,[0 2],[0 2])
the listener was not triggered
Fig 3. The callback ReposFootPrint is triggered once the XLim property is manually set, placing back the footprint to its original location (this should be automatic)
Adam Danz
Adam Danz on 15 Apr 2021
Edited: Adam Danz on 15 Apr 2021
In Matlab r2021a and later, see this community highlight for a demonstration of the new LimitsChangedFcn that is easier to use and more reliable than applying a listener to the xlim property. The demo moves a text object any time the axis limits change. That can easily be applied to your footprints.

Sign in to comment.

Answers (0)

Categories

Find more on Labels and Annotations in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!