Format Bar Graph Matlab

3 visualizaciones (últimos 30 días)
Felix
Felix el 1 de Sept. de 2015
Comentada: Felix el 1 de Sept. de 2015
I use the following code to generate a bar plot:
% generate numbers to plot
a = rand(20,1);
b = rand(20,1)+1;
[i, ~]= size(a);
x = (1:i)';
M =4;
hold on
% generate bar plot for the high values
for k = 0: M
D(k+1,1) = bar((4*k+1 : 4*k+4),b(4*k+1 : 4*k+4),0.3);
set(D(k+1,1),'FaceColor',[0.1*k 0.25*k 1-0.25*k]);
end
% generate bar plot for the smaller values in front
for k = 0: M
E(k+1,1) = bar((4*k+1 : 4*k+4),a(4*k+1 : 4*k+4),0.5);
set(E(k+1,1),'FaceColor',[0.1*k 0.15*k 0.4-0.1*k]);
end
% style
xLabl ={'1', '5', '10' , '20', '1', '5', '10' , '20', '1', '5', '10' , '20', '1', '5', '10' , '20', '1', '5', '10' , '20'};
set(gca, 'XTick', x, 'XTickLabel', xLabl);
axis([0, inf, 0,inf]);
grid;
legend('T_p = 0.5', 'T_p = 1.0', 'T_p = 1.5', 'T_p = 2.0', 'T_p = 3.0', 'Location','northwest');
xlabel('N');
I plot the maximum and mean values of my test results for different combinations of the paramters N and T_p. Results with the same choice for T_p are plotted in the same color, as indicated in the legend. But the color varies slightly for the mean and max value. I was wondering if it is possible to extend the legend to display both corresponding bar colors to the choice of T_p. It should look something like this:
What I am looking for is to extent the legend. As I tried to show with my additions from paint. I want to use the colors of the bars in the background in the legend and specifically for the same values of T_P in the same row. Idealy I could distinguish these to coloumns of the legend with the coloum caption 'mean' and 'max'. Is this possible?

Respuestas (1)

Image Analyst
Image Analyst el 1 de Sept. de 2015
You can vary the color of each bar individually, as shown in my attached demo.
  1 comentario
Felix
Felix el 1 de Sept. de 2015
Thanks for your reply. Unfortunately this is not what I am looking for. I updated the problem description, to hopefully facilitate the understanding of my problem.

Iniciar sesión para comentar.

Categorías

Más información sobre Legend 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