Effacer les filtres
Effacer les filtres

Matlab 2015a: how can I adjust the markers size in the legend?

5 vues (au cours des 30 derniers jours)
Luc
Luc le 21 Août 2015
Commenté : Walter Roberson le 16 Sep 2017
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

Réponses (2)

Walter Roberson
Walter Roberson le 21 Août 2015
  1 commentaire
Luc
Luc le 21 Août 2015
Yes I know, I commented on that question too. Hopefully, someone will solve this issue soon.

Connectez-vous pour commenter.


David Rosenbaum
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

Community Treasure Hunt

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

Start Hunting!

Translated by