Effacer les filtres
Effacer les filtres

Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

Legend needs to be turned off and on again to be shown correctly

1 vue (au cours des 30 derniers jours)
Lucas-Raphael Müller
Lucas-Raphael Müller le 9 Juin 2016
Clôturé : MATLAB Answer Bot le 20 Août 2021
Hi, I've got a problem using the legend for a matlab plot: I plot multiple plots in one figure and need to dispay the legend for some plots and for some not. Here is a part of code I use:
figure
for i=1:100
p(i) = plot(x,y, 'DisplayName', name{i});
legend('-DynamicLegend');
hold all;
if i~= 1 && i~= 100
set(get(get(p(i),'Annotation'),'LegendInformation'),'IconDisplayStyle','off');
end
end
p(i + 1) = plot(a,b, 'DisplayName', 'test1');
p(i + 2) = plot(c,d, 'DisplayName', 'test2');
hold off;
The problem is that the figure which is shown only shows the name name{1} and name{100} and without the box. As soon as I disable the legend in the figure (after it has been produced by matlab) and enable it again the legend is shown with a box and with name{1}, name{100} and test1 and test2 which is correct. Am I missing something or is it a bug? Is there maybe a workaround to disable and enable automatically?
Cheers

Réponses (0)

Cette question est clôturée.

Community Treasure Hunt

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

Start Hunting!

Translated by