strange symbol instead of legend color

3 views (last 30 days)
I am plotting a bar graph but it shows strange symbol instead of legend color.(All legend with title scoliosis)
model_series =[6.8340 6.9400 7.9567 8.0590 8.6337 8.4850 9.6813 9.6110
6.9900 7.3850 8.1000 7.9670 8.9988 8.8450 9.8800 9.2950
7.3859 7.6550 8.6808 8.4840 9.1937 9.1640 10.4041 9.7670
7.7200 8.3900 9.2600 8.9650 9.8925 10.0510 11.2875 10.9370
8.4460 8.5537 9.6750 9.5830 10.7713 10.8390 12.0888 11.7120];
model_error= [0.3658 0.5786 0.3906 0.5330 0.3863 0.6931 0.3600 0.5593
0.4482 0.9325 0.5073 0.3567 0.4530 0.4624 0.3595 0.7508
0.4261 0.7700 0.4834 0.2987 0.5723 0.5778 0.3924 0.8415
0.2262 0.9505 0.3509 0.5372 0.3625 0.5791 0.3269 0.8313
0.2159 0.7532 0.4219 0.3150 0.4645 0.5528 0.2776 0.8970];
colorList = [0 0.45 0.74;0.85 0.33 0.1;0.93 0.69 0.13;0.49 0.18 0.56;0.47 0.67 0.19;0.3 0.75 0.93; 0.64 0.08 0.18;0.72 0.27 1];
offset = 1;
skip = 1;
figure
xlim([0 14])
hold on
xloc = 0;
for i = 1:size(model_series,1)
for j = 1:size(model_series,2)
xloc = xloc + offset;
barh(xloc,model_series(i,j),1,'FaceColor',colorList(j,:))
errorbar(model_series(i,j),xloc,model_error(i,j),'k','Horizontal','LineWidth',1.3)
end
xloc = xloc + skip;
end
set(gca,'yTick',[4.5 13.5 22.5 31.5 40.5])
set(gca,'YTickLabel',{'T5','T6','T7','T8','T9'},'FontSize',19,'FontWeight','bold')
% X and Y labels
ylabel ('Thoracic Spine Level','FontSize',19,'FontWeight','bold');
xlabel ('Right Vertebral Body Height (mm)','FontSize',19,'FontWeight','bold');
% Creating a legend and placing it outside the bar plot
lg = legend('Normal 7wks','Scoliotic 7wks',....
'Normal 11wks','Scoliotic 11wks', 'Normal 14wks','Scoliotic 14wks', ...
'Normal 28wks','Scoliotic 28wks','AutoUpdate','off');
lg.Location = 'westoutside';
lg.Orientation = 'Horizontal'; lg.FontSize=10;
Legend_Figure.jpg
  3 Comments
Osi fri
Osi fri on 24 Apr 2019
Yes I have just added both ( code and a picture).
Thanks!
Star Strider
Star Strider on 24 Apr 2019
Those seem to me to be the legend entries for the errorbar plots.

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 24 Apr 2019
The strange lines in the legend are the legend entries for the errorbar()
If you only want the bar() call to be legend'd then record the handles of the bar() and pass them to legend()

More Answers (0)

Community Treasure Hunt

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

Start Hunting!