Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: Legend problem in bar graph
Replies: 0  

Advanced Search

Back to Topic List Back to Topic List  
Kate J.

Posts: 177
Registered: 6/9/11
Legend problem in bar graph
Posted: Dec 11, 2012 3:19 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

My code below successfully creates a bar plot that contains 5 bars, each with a unique color:

-------------------------------------
bar_h = bar(myData);
bar_child=get(bar_h,'Children');
set(bar_child,'CDataMapping','direct');
mycolor=[0 0 0;
1 0 0;
1 0 1;
1 1 0;
0 1 0];
index = [1 2 3 4 5];
set(bar_child, 'CData',index);
colormap(mycolor);
hold on;
h2 = errorbar(myData, myDataErrors);
set(h2,'linestyle','none');
---------------------------------------

However, I'm having problems with adding a legend; using the format

legend('label1','label2','label3','label4','label5');

always results in the following behavior:
~ the first label appears correctly, with the correctly-colored box next to it
~ the second label's name appears, but there is no colored box next to it
~ the other 3 labels are missing from the legend

If I insert the handle name as the first argument to the legend() call, the behavior only worsens, now additionally eliminating the second label from the legend, as well...

Is anyone familiar with what I'm doing wrong? Thanks in advance for any advice.



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.