And the only thing I managed to do is the generate the figure above in the original question. Many thanks
Info
This question is closed. Reopen it to edit or answer.
handling colours in barplots
1 view (last 30 days)
Show older comments
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/152769/image.png)
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 Comment
Answers (1)
Star Strider
on 18 Dec 2015
I don’t understand what you want to do. Experiment with the bar3 plot to see if you can do what you want.
2 Comments
Star Strider
on 18 Dec 2015
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.)
This question is closed.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!