フィルターのクリア

Display interactive legend for separate multiple bars

2 ビュー (過去 30 日間)
Mario
Mario 2018 年 8 月 30 日
コメント済み: Mario 2018 年 8 月 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 Center および File ExchangeLegend についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by