Locking the Legend even if the object is deleted
Show older comments
Hello,
I want the AutoUpdate of my legend to be "off" no matter whether I delete an object from the axes, but:
(since R2022b): If you delete an object from the axes, the legend updates to reflect the change regardless of whether this property (AutoUpdate) is set to "on" or "off".
I have programmed a simulation where the legend of the axes should stay as it is, no matter which objects you delete in the plot. Do you have any idea how I can implement this in newer versions of Matlab?
Warm regards,
Ruben
Accepted Answer
More Answers (1)
Bjorn Gustavsson
on 7 Feb 2023
0 votes
If you explicitly set the axis of the plot, then you can hide objects outside the visible are and use their handles for the legend. That way it doesn't matter what objects are still "alive" in your active plot. This is a fairly cludgy way to get around this, but I've found it useful to explain the meaning of different line-widths, line-styles when they display different properties across all lines.
1 Comment
Ruben Kopischke
on 7 Feb 2023
Categories
Find more on Legend 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!

