how to write the legend in bar chart

1 次查看(过去 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)

采纳的回答

Ameer Hamza
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'})
  14 个评论
Ameer Hamza
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 CenterFile Exchange 中查找有关 Data Distribution Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by