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!