how to write the legend in bar chart

2 Ansichten (letzte 30 Tage)
Ibrahim AlZoubi
Ibrahim AlZoubi am 3 Mai 2020
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)

Akzeptierte Antwort

Ameer Hamza
Ameer Hamza am 3 Mai 2020
Bearbeitet: Ameer Hamza am 3 Mai 2020
Try this
y =[44,55,54];
hold on
for i=1:numel(y)
bar(i, y(i))
end
legend({'first', 'second', 'third'})
  14 Kommentare
Ameer Hamza
Ameer Hamza am 3 Mai 2020
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'})
Ibrahim AlZoubi
Ibrahim AlZoubi am 3 Mai 2020
thank you sir it worked thank you!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Data Distribution Plots finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by