![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/290036/image.png)
how to write the legend in bar chart
2 次查看(过去 30 天)
显示 更早的评论
how to add legend for the first, second and third column?
this is the code:
y =[44,55,54] ;
b = bar(y,0.5);
bar(y)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/290033/image.png)
0 个评论
采纳的回答
Ameer Hamza
2020-5-3
编辑:Ameer Hamza
2020-5-3
Try this
y =[44,55,54];
hold on
for i=1:numel(y)
bar(i, y(i))
end
legend({'first', 'second', 'third'})
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/290036/image.png)
14 个评论
Ameer Hamza
2020-5-3
You can replace A, B and C with what you want
y =[44,55,54];
hold on
for i=1:numel(y)
bar(i, y(i))
end
xticks(1:numel(y))
xticklabels({'44', '55', '54'})
legend({'first', 'second', 'third'})
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Legend 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!