how to label each row of these 3 saws:
i want to call them: A,B, and C.
also how to color each raw?
this is my code:
x =[208,237,248];
barh (x)
axis square

 Akzeptierte Antwort

Benjamin Colety
Benjamin Colety am 6 Mai 2020

1 Stimme

try this for the labels
labels={'A'; 'B'; 'C' };
barh(x)
set(gca,'yticklabel',labels)

4 Kommentare

Ibrahim AlZoubi
Ibrahim AlZoubi am 6 Mai 2020
do you have any idea about how to change these colors?
Tommy
Tommy am 6 Mai 2020
How about the same idea from Ameer's answer here?
x =[208,237,248];
hold on
for i=1:numel(x)
barh(i, x(i))
end
axis square
yticks(1:numel(x))
yticklabels({'A'; 'B'; 'C'})
ibrahim alzoubi
ibrahim alzoubi am 6 Mai 2020
how to change the colors?
Tommy
Tommy am 6 Mai 2020
You can set the FaceColor property to any rgb value:
x =[208,237,248];
colors = [ 1 0 0 ; % red
0 1 0 ; % blue
0 0 1 ]; % green
hold on
for i=1:numel(x)
barh(i, x(i), 'FaceColor', colors(i,:))
end
axis square
yticks(1:numel(x))
yticklabels({'A'; 'B'; 'C'})
Or, honestly this is simpler:
x =[208,237,248];
colors = [ 1 0 0 ; % red
0 1 0 ; % blue
0 0 1 ]; % green
barh(x, 'FaceColor', 'flat', 'CData', colors);
axis square
yticklabels({'A'; 'B'; 'C'})

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Discrete Data Plots finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by