Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

handling colours in barplots

3 Ansichten (letzte 30 Tage)
Patricia  Bracer
Patricia Bracer am 18 Dez. 2015
Geschlossen: MATLAB Answer Bot am 20 Aug. 2021
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 Kommentar
Patricia  Bracer
Patricia Bracer am 18 Dez. 2015
And the only thing I managed to do is the generate the figure above in the original question. Many thanks

Antworten (1)

Star Strider
Star Strider am 18 Dez. 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 Kommentare
Patricia  Bracer
Patricia Bracer am 18 Dez. 2015
Bearbeitet: Patricia Bracer am 18 Dez. 2015
I want to create something exactly like the attached figure
Star Strider
Star Strider am 18 Dez. 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.)

Diese Frage ist geschlossen.

Community Treasure Hunt

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

Start Hunting!

Translated by