Matlab 2015a: how can I adjust the markers size in the legend?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (2)
Walter Roberson
le 21 Août 2015
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
le 15 Sep 2017
Modifié(e) : Walter Roberson
le 16 Sep 2017
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
Voir également
Catégories
En savoir plus sur Legend dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!