matlab : suppress legend entry without removing from Plot Browser
Date: 2022-12-01 12:39:38
One can suppress a legend entry for a line object h
by executing h.HandleVisibility='off'
or h.Annotation.LegendInformation.IconDisplayStyle='off'
. However, both actions also prevent the curve from appearing in Matlab's Plot Browser user interface, and thus display of the curve cannot be interactively toggled.
Is there any way to suppress a legend entry for a given curve without also removing the ability to toggle display of that curve in the Plot Browser user interface?
Answers:
You can also turn off handle visibility. This is way easier than having to set every plot as h1 = ...
Example:
x1 = randperm(10); y = randperm(10); x2 = randperm(10); plot(x1, y, '-', 'Color', 'black', 'HandleVisibility', 'off') hold on plot(x2, y, '-', 'Color', 'green', 'DisplayName', 'Put This In Legend') lgd = legend; set(lgd, 'Location', 'best')