
How do I change the colours of the bars in a bar plot?
267 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Lodewijk Pleij
el 29 de Abr. de 2019
So I have 2 samples that have 4 layers each. I want to make a bar graph of the layers of every sample next to the value of the control sample. I want change the colours of every bar. How do I do this?
clear all
close all
clc
%% LOI Data
SWC = 6.70;
SWN1 = 18.8;
SWN2 = 19.3;
SWN3 = 11.3;
SWN4 = 4.59;
KHC = 9.87;
KHN1 = 20.0;
KHN2 = 16.7;
KHN3 = 9.98;
KHN4 = 10.1;
%% Plot
LOI = [ SWN1,SWC,KHC,KHN1; SWN2,SWC,KHC,KHN2; SWN3,SWC,KHC,KHN3; SWN4,SWC,KHC,KHN4];
bar(LOI);
legend('SW','SW Control','KH Control','KH')
xlabel('Layer [#]')
ylabel('LOI [%]')

So this is the picture of the graph. The colours of every layer should arrange like this: [blue, light blue, light red, red]
0 comentarios
Respuesta aceptada
Adam Danz
el 29 de Abr. de 2019
Editada: Adam Danz
el 1 de Mayo de 2019
Use the handles to your bar chart to change the colors.
bh = bar(LOI);
bh(1).FaceColor = [0 0 1]; %blue
bh(2).FaceColor = [0.67578 0.84375 0.89844]; %light blue
bh(3).FaceColor = [1 0.75 0.79297]; %pink
bh(4).FaceColor = [1 0 0]; %red

0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!