Fixing the legend of a bar graph
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Alberto Acri
am 6 Aug. 2023
Beantwortet: the cyclist
am 6 Aug. 2023
Hi! I need to better arrange the legend of a bar graph. It is currently plotted like this:
load CountArray_A.mat
x = CountArray_A(:,1).';
y = CountArray_A(:,2);
figure();
graph = barh(x,y,'FaceColor',[1 0 0],'EdgeColor',[0 0 0]);
name = "saagagagasgadgadgadg ddsbds fbsfs sdbsdsz dhwh ddadgada adggdv";
legend({name},'Location','northeast','Orientation','horizontal')
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1451617/image.png)
I would like to either change the legend like this (if possible):
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1451622/image.png)
0 Kommentare
Akzeptierte Antwort
the cyclist
am 6 Aug. 2023
Here is one way:
load CountArray_A.mat
x = CountArray_A(:,1).';
y = CountArray_A(:,2);
figure();
graph = barh(x,y,'FaceColor',[1 0 0],'EdgeColor',[0 0 0]);
name = "saagagagasgadgadgadg" + newline + "ddsbds fbsfs sdbsdsz dhwh ddadgada adggdv"; % Added newline
legend(name,'Location','northeast','Orientation','horizontal') % Removed unnecessary cell
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Legend finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!