I've attached a 'XLim' listener to an axes object.
I had been previously using a timer due to issues with catching the events appropriately (for reasons I can't exactly remember). Now they're starting to come back to me ...
Here's some basic test code (from 2017b):
ax = gca;
plot(1:100)
L1 = addlistener(ax, 'XLim', 'PostSet', @(x,y)disp(y.AffectedObject.XLim));
When I zoom in my listener fires properly. However, when I double-click to reset the zoom (or right click and reset) no listener is fired! The 'XLim' property clearly changed but Matlab doesn't seem to care to inform me of this fact.
This seems like a bug to me. Looking at SO there is a suggestion that I listen to the zoom callback, but I'd rather not touch any callbacks since I might need 2 or more callbacks for a single axes.
Even more surprising is that by linking the axes an event is now fired on resetting the zoom. This seems to persist even if I turn the linking off.
clf
ax = gca;
plot(1:100)
L1 = addlistener(ax, 'XLim', 'PostSet', @(x,y)disp(y.AffectedObject.XLim));
linkaxes(ax,'x')
linkaxes(ax,'x','off')
Questions are:
- How can I get a listener event for zoom reset (and pan reset) that is resistant to accidental overwriting (i.e. most likely by avoiding a single callback property)
- If the behavior is not a bug, why? See remark below on blog post.
- Why does running linkaxes fix this problem?
- Is there a way of accomplishing whatever the linkaxes function is doing without actually needing to modify the linkaxes behavior of the axes?
Update:
If you plot again the event stops getting thrown in response to resetting the zoom. ¯\_(ツ)_/¯
clf
ax = gca;
plot(1:100)
L1 = addlistener(ax, 'XLim', 'PostSet', @(x,y)disp(y.AffectedObject.XLim));
linkaxes(ax,'x')
linkaxes(ax,'x','off')
plot(1:100)
0 Comments
Sign in to comment.