Plotting confidence intervals with only one serie in the legend
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello,
In a figure, I plotted a series of data. After having calculated the average, lower and upper limits of both 95% and 99.4% confidence intervals, I added them to the figure. Then, I inserted the legend. Here, all the 6 series' labels appear. What I would then like is to remove from the legend labels, one of the 2 labels corresponding to 95% confidence intervals and one of the 2 labels of the 99.4%. But, Matlab doesn't allow me to do it. Could you help e to solve this problem ? Thanks and best regards.
0 commentaires
Réponse acceptée
the cyclist
le 8 Juin 2012
There are several different approaches to doing this, but you didn't share your code, so it is not possible to know which method fits best with how your code currently operates. However, the key is to only supply the legend() command with the handles for the objects you want to appear in the legend. Here's a simple example that illustrates the approach. I hope you can figure out how to work the same approach into your code:
figure
hold on
h1 = plot(1:100,rand(1,100)+1,'g-');
h2 = plot(1:100,rand(1,100), 'b-');
h3 = plot(1:100,rand(1,100)-1,'r-');
legend([h1 h2],{'top','middle'}); % I did not include the handle for the bottom line
2 commentaires
Tom Lane
le 12 Juin 2012
Instead of inserting the legend from the figure toolbar, try getting handles from the plot commands as the cyclist suggests, and supplying labels for the handles that you want to include in the legend.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Legend dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!