Borrar filtros
Borrar filtros

change color of bar plot

1 visualización (últimos 30 días)
mohammad
mohammad el 20 de Feb. de 2023
Respondida: Voss el 20 de Feb. de 2023
how can i change my bar plot and define legend like follwing picure ?

Respuestas (2)

Sulaymon Eshkabilov
Sulaymon Eshkabilov el 20 de Feb. de 2023
Here is one example how to get such bar chart:
y = [12 22 23; 21 25 26; 24 18 19; 22 17 15];
bar(y,'stacked')
legend({'Set # 1', 'Set # 2', 'Set # 3'}, 'Orientation','horizontal')
ax = gca;
ax.YGrid = 'on';
ax.GridLineStyle = '--';
xlabel('Orders')
ylabel('Magnitude')
  1 comentario
mohammad
mohammad el 20 de Feb. de 2023
thank you but how can i change their color

Iniciar sesión para comentar.


Voss
Voss el 20 de Feb. de 2023
y = [12 22 23; 21 25 26; 24 18 19; 22 17 15];
h = bar(y,'stacked'); % capture the bar objects into variable 'h'
legend({'Set # 1', 'Set # 2', 'Set # 3'}, 'Orientation','horizontal')
ax = gca;
ax.YGrid = 'on';
ax.GridLineStyle = '--';
xlabel('Orders')
ylabel('Magnitude')
% change the bar colors:
h(1).FaceColor = 'k';
h(2).FaceColor = [0 0.5 0];
h(2).FaceColor = 'm';

Categorías

Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by