bar graph color and error

조회 수: 2 (최근 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.
  댓글 수: 2
changmin lim
changmin lim 2024년 3월 11일
Thank you!!
This helped me a lot
Voss
Voss 2024년 3월 11일
You're welcome!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile 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!

Translated by