Creating a Legend for Two Bar Plots (Plotted Together on Same Figure)
Show older comments
Hi, I am having trouble getting a legend that incorporates both bar graphs (one white & one black) that are plotted together on the same figure using 'hold on'. Each bar also has an error bar. An example of my code is:
figure;
errorbar(x, meanValue, lowerError, upperError, 'k', 'LineStyle', 'none');
hold on;
bar(x, meanValue, 'w');
errorbar(x, -meanValue2, -upperError2, -lowerError, 'k', 'LineStyle', 'none');
bar(x, -meanValue2, 'k');
legend('Label1','Label2');
When I do this, the legend has no color for Label1 (black), but has a color for Label2 (white). How can I get the black color to show up in the legend for Label1. Any help would be greatly appreciated. Thank you.
Accepted Answer
More Answers (0)
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!