Azzera filtri
Azzera filtri

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

5 visualizzazioni (ultimi 30 giorni)
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

Risposte (2)

Walter Roberson
Walter Roberson il 21 Ago 2015
  1 Commento
Luc
Luc il 21 Ago 2015
Yes I know, I commented on that question too. Hopefully, someone will solve this issue soon.

Accedi per commentare.


David Rosenbaum
David Rosenbaum il 15 Set 2017
Modificato: Walter Roberson il 16 Set 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