bar graph color and error
2 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
Voss
on 10 Mar 2024
Edited: Voss
on 10 Mar 2024
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.
More Answers (0)
See Also
Categories
Find more on Specifying Target for Graphics Output in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!