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!