Plotting confidence intervals with only one serie in the legend
1 view (last 30 days)
Show older comments
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 Comments
Accepted Answer
the cyclist
on 8 Jun 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 Comments
Tom Lane
on 12 Jun 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.
More Answers (0)
See Also
Categories
Find more on Legend in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!