Display interactive legend for separate multiple bars

2 次查看(过去 30 天)
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 个评论
Mario
Mario 2018-8-30
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

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Legend 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by