Display interactive legend for separate multiple bars
3 views (last 30 days)
Show older comments
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!
Answers (0)
See Also
Categories
Find more on Legend in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!