bar graph color and error

1 次查看(过去 30 天)
changmin lim
changmin lim 2024-3-10
评论: Voss 2024-3-11
Hello, I am recently workging on plotting bar graph.
xticklabels({'P','As','Sb','Se','Te'})
x = [1,2,3,4,5]
y = [5.03E-11 5.35E-11 4.55E-11 8.85E-11 6.26E-11;
5.03E-11 5.35E-11 4.58E-11 8.95E-11 6.26E-11;
3.73E-11 4.06E-11 3.81E-11 5.82E-11 3.75E-11;
3.73E-11 4.06E-11 3.81E-11 5.85E-11 3.75E-11;
4.30E-11 4.66E-11 3.44E-11 1.15E-10 2.78E-10;
4.30E-11 4.66E-11 3.44E-11 1.15E-10 2.78E-10]
h=bar(x,y,'FaceColor','flat')
xticklabels({'P','As','Sb','Se','Te'})
a = get(gca,'xticklabels');
set(gca,'XTickLabel',a,'fontsize',13)
set(gca, 'yscale','log')
this is the code that I used for this plot
However, I am intending to change the colors into groups. For example, changing the all colors in P into red, changing all colors in As into blue, changing all colors in Sb into green etc.
Also, in the Sb group, 3.44E-11 part doesn't appear in the graph and I cannot figure out why.
Can anyone help me with group color change and Sb group error?
Thank you

采纳的回答

Voss
Voss 2024-3-10
编辑:Voss 2024-3-10
x = [1,2,3,4,5];
y = [5.03E-11 5.35E-11 4.55E-11 8.85E-11 6.26E-11;
5.03E-11 5.35E-11 4.58E-11 8.95E-11 6.26E-11;
3.73E-11 4.06E-11 3.81E-11 5.82E-11 3.75E-11;
3.73E-11 4.06E-11 3.81E-11 5.85E-11 3.75E-11;
4.30E-11 4.66E-11 3.44E-11 1.15E-10 2.78E-10;
4.30E-11 4.66E-11 3.44E-11 1.15E-10 2.78E-10];
% red, blue, green, yellow, magenta:
colors = [1,0,0;0,0,1;0,1,0;1,1,0;1,0,1];
h=bar(x,y,'FaceColor','flat','CData',colors);
xticklabels({'P','As','Sb','Se','Te'})
set(gca,'fontsize',13,'yscale','log')
The reason you don't see the bar at 3.44E-11 is because that's the lower y-limit of your axes. You can adjust the limits with the ylim() function.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by