bar graph color and error
2 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
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 Center 和 File Exchange 中查找有关 Specifying Target for Graphics Output 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!