How do I listen for when new axes are added to a figure?
Show older comments
I would like to know when new axes are added to a figure. The axes will always have the figure as a parent. I have tried using the ChildAdded event listener, but this does not trigger when, for example, the subplot function creates a new set of axes.
2 Comments
Steven Lord
on 6 Jun 2019
How would you use this information if it was available? What's your use case? Knowing what your ultimate goal is may allow us to offer a better solution than trying to listen for new axes being added.
Matthew
on 6 Jun 2019
Accepted Answer
More Answers (1)
Daniel Dolan
on 28 Oct 2020
Matthew,
I've been looking for a similar feature that keeps a particular axes on top of everything else. The ChildAdded listener triggers on menu, panel, and uicontrol additions, but not axes creation.
The best I have come up with is to monitor the figure's CurrentAxes property.
L=listener(gcf,'CurrentAxes','PostSet',@(~,~) disp('current axes changed'))
This appears to work for axes and subplot calls.
Dan
Categories
Find more on Creating, Deleting, and Querying Graphics Objects 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!