Remove legend from patches in Matlab
5 ビュー (過去 30 日間)
古いコメントを表示
I create hundreds of patches using patch() in my subplots.
I have 5 subplots, 4 of which have legend entries.
I create several figures all with patches using a for loop.
My figure with subplots + patches, comes up with not only the legend entries for the data, but also from the patches which is covering my plot!
I tried the following but nothing has worked:
% loop to create figures of the subplot with patches
for i=1:length(ix)
... % code to create plot in a figure
for j=1:length(iy) % numbering for patches
legend('off');
set(0,'DefaultLegendAutoUpdate','off');
... % code to create patches on all subplots
end
end
on other matlab questions, supposedly doing legend('off') and set(0,'DefaultLegendAutoUpdate','off') solved the problem, however it just isn't working for me. Anybody help?
0 件のコメント
回答 (1 件)
Steven Lord
2020 年 9 月 15 日
Specify the handles of the objects that you want to see in the legend when you create it.
x = 0:360;
axis([0 360 -1 1])
hold on
sineCurves = gobjects(1, 5);
for k = 1:5
sineCurves(k) = plot(x, sind(k*x), 'DisplayName', "sine of " + k + "*x");
end
legend(sineCurves([1 3 4]))
The curves for the sine of 2*x and 5*x appear in the plot but not in the legend.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Legend についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!