Display interactive legend for separate multiple bars

4 visualizaciones (últimos 30 días)
Mario
Mario el 30 de Ag. de 2018
Comentada: Mario el 30 de Ag. de 2018
Hi,
I have a large number of separate bars plotted and I am trying to find a way to add a interactive legend to all those separate bar plots that is displaying their number (for example: no. 1, no. 2, no. 3,...etc.).
I wrote a code below that is somewhat close to the solution, but I haven't figured it out yet:
for i8=1:Br_snimaka
figure,bar(A33(i8).Var1); % A33 variable containing data for bar plots
set(gcf, 'Color', [1,1,1]);
xlabel('Broj regiona','FontSize', 20);
ylabel('Standardna devijacija','FontSize', 20);
ylim([0 25]);
xlim([0 7]);
for k=1:Br_snimaka
leg{k}=sprintf('no. %d',k);
end
legend(leg);
end
I tried different solutions where I tried to put legend in a for loop, but without no success. With this code above I get the same legend displayed (no. 1) on all bar plots, and at the end I get an error "Warning: Ignoring extra legend entries. > In legend at 286 "
Any help would be greatly appreciated.
Thanks!
  1 comentario
Mario
Mario el 30 de Ag. de 2018
I found a solution myself, here is the code (cleaned from my required inputs) if anyone ever needs it:
for i8=1:image_no
figure,
b=bar(A33(i8).Var1);
leg{i8}=sprintf('no. %d',i8);
legend(b,leg{i8});
end

Iniciar sesión para comentar.

Respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by