Matlab 2015a: how can I adjust the markers size in the legend?
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi, I am using scatter function in matlab 2015a and whenever I create a legend for my figures, the marker size is always smaller than on the plot itself. I have found no clear way of fixing this while searching around here.
Anyone can help?
Thanks
댓글 수: 0
답변 (2개)
Walter Roberson
2015년 8월 21일
We do not seem to have found a way to do that as yet. See http://uk.mathworks.com/matlabcentral/answers/97779-why-is-the-marker-size-in-the-legend-of-a-scatter-plot-not-equal-to-the-marker-size-in-the-plot
David Rosenbaum
2017년 9월 15일
편집: Walter Roberson
2017년 9월 16일
You can solve this problem by plotting your points as you would like them to appear in the legend, then call for the legend, then replot the points in the way you'd like them to appear, having set legend 'Autoupdate' to 'off'. Finally, if the finally plotted point sizes are smaller than the originally plotted point sizes, you should first "erase" the points by showing them in a color that matches the background (typically white), and then replot them. The code in which I use this has some added material that might be useful.
close all
clear all
commandwindow
clc
figure
hold on
xlim_offset=0;
ms=14; % markersize
x=[1:101];
alpha=[-.5 -1];
max_salary=10;
fs=12;
for ai=1:size(alpha,2)
y=max_salary*x.^alpha(ai);
if ai==1
plot(x,y,'b.-','markersize', ms, 'displayname','Company A');
else
plot(x,y,'r.-','markersize', ms, 'displayname','Company B');
end
end
legend('show','location','northeast')
get(legend)
set(legend,'FontSize',10.5,'color','w')
set(legend,'AutoUpdate','off')
xlabel('Income Rank')
ylabel('Salary (thousands of dollars)')
set(gca,'xtick',[1:10:101])
set(gca,'xticklabel',[1:10:101])
xlim([min(x)-xlim_offset max(x)+xlim_offset])
% Now re-plot with new marker size
new_ms=ms-6;
for ai=1:size(alpha,2)
y=max_salary*x.^alpha(ai);
if ai==1
if new_ms<ms
plot(x,y,'w.-','markersize', ms);
end
plot(x,y,'b.-','markersize', new_ms);
else
if new_ms<ms
plot(x,y,'w.-','markersize', ms);
end
plot(x,y,'r.-','markersize', new_ms);
end
end
참고 항목
카테고리
Help Center 및 File Exchange에서 Legend에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!