Example code:
x=[1:1:10];
figure;
hplot = plot(x,x,'.k');
h_for_legend = hplot;
set(hplot,'MarkerSize',2); % small size marker
set(h_for_legend,'MarkerSize',12); % attempt to get larger marker for legend
legend_string = 'my data';
legend(h_for_legend,legend_string);
I was hoping that the markers on the plot (handle hplot) would be size 2, and the marker in the legend (handle h_for_legend) would be size 12 so it would be visible. A single size 2 marker in the legend is too small. But the datapoints in the plot inheirit the marker size that I gave the legend (12). How can I get them to be different in the plot vs. the legend (and change other attributes as well if I want)?
Thanks very much.
Hi,
One possible way of changing the 'MarkerSize' of the legend would be as follows:
x=[1:1:10];
figure;
hplot = plot(x,x,'.k');
set(hplot,'MarkerSize',10);
legend_string = 'my data';
%%NEW
l=legend(hplot,legend_string);
%l=findobj(gcf,'tag','legend') % Alternate way of finding the legend handle if not
% known in advance.
a=get(l,'children');
%a(1) corresponds to the marker object
set(a(1),'markersize',20); % This line changes the legend marker size
%%NEW
You can do a GET on the legend handle or on other objects of legend such as 'text', marker etc. to get more information on available properties of each of these objects.
I hope this helps !
-Jimy
"Jimy " <jimy...@mathworks.com> wrote in message <ghq3qs$q36$1...@fred.mathworks.com>...