Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

handling colours in barplots

조회 수: 1 (최근 30일)
Patricia  Bracer
Patricia Bracer 2015년 12월 18일
마감: MATLAB Answer Bot 2021년 8월 20일
Dear all
I have 24 parameters (dEp in the code). In the x axis each set of 4 parameters represents a region (e.g.region A , i have 6 regions in total). So to start with, for every 4 bars i need to have a different label in the x-axis
Each of the four bars of the the 6 regions, correspond to different parameters so each colour of the bar should be different but the colours should be then repeated in each region. (please look colours in the attached figure)
Can you please help me to do the plot in a more optimal way, set the x axis correctly and finally have a colour index explaining the 4 different colours of the bars?
Thank you
bar(1,dEp(1),'y') hold on bar(2,dEp(2),'c') hold on bar(3,dEp(3),'r') hold on bar(4,dEp(4),'b') bar(5,dEp(5),'y') hold on bar(6,dEp(6),'c') hold on bar(7,dEp(7),'r') hold on bar(8,dEp(8),'b') bar(9,dEp(9),'y') hold on bar(10,dEp(10),'c') hold on bar(11,dEp(11),'r') hold on bar(12,dEp(12),'b') bar(13,dEp(13),'y') hold on bar(14,dEp(14),'c') hold on bar(15,dEp(15),'r') hold on bar(16,dEp(16),'b') bar(17,dEp(17),'y') hold on bar(18,dEp(18),'c') hold on bar(19,dEp(19),'r') hold on bar(20,dEp(20),'b') bar(21,dEp(21),'y') hold on bar(22,dEp(22),'c') hold on bar(23,dEp(23),'r') hold on bar(24,dEp(24),'b')
set(gca,'XTickLabel',{'region A', 'region B', 'region C', 'region D','region E','region F'})
  댓글 수: 1
Patricia  Bracer
Patricia Bracer 2015년 12월 18일
And the only thing I managed to do is the generate the figure above in the original question. Many thanks

답변 (1개)

Star Strider
Star Strider 2015년 12월 18일
I don’t understand what you want to do. Experiment with the bar3 plot to see if you can do what you want.
  댓글 수: 2
Patricia  Bracer
Patricia Bracer 2015년 12월 18일
편집: Patricia Bracer 2015년 12월 18일
I want to create something exactly like the attached figure
Star Strider
Star Strider 2015년 12월 18일
That makes it much easier.
Arrange your data in a matrix, and then use the 'grouped' option:
data = randi(9, 4, 6); % 4x6 Matrix
figure(1)
bar(data, 'grouped')
Experiment with that with your data.
If you need help getting it as you want, attach your data here, and explain it so I can understand how it is organised. (Use the ‘paperclip’ icon, and complete both the ‘Choose file’ and ‘Attach file’ steps.)

이 질문은 마감되었습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by