legend that has different marker size in matlab

To create a legend with different marker sizes in Matlab, you can use the 'MarkerSize' property combined with the 'legend' function. Here's an example:

main.m
% Generate some random data
x = 1:10;
y1 = rand(1,10);
y2 = rand(1,10);

% Plot the data with different marker sizes
figure
hold on
plot(x, y1, 'o', 'MarkerSize', 5)
plot(x, y2, 'o', 'MarkerSize', 10)
hold off

% Create the legend with marker sizes
legend('Data 1', 'Data 2')

% Adjust the legend marker size
lgd = findobj(gcf, 'Type', 'Legend');
lgd.MarkerSize = [5, 10];
373 chars
19 lines

In this example, the plot function is used to create two sets of data points with different marker sizes. The 'MarkerSize' property is set to 5 for the first set and 10 for the second set.

After plotting the data, the legend function is called to create the legend. By default, the legend will have markers with the same size as the ones in the plot.

To adjust the marker sizes in the legend, you can find the Legend object in the current figure using findobj and set its MarkerSize property to an array of values corresponding to the marker sizes in the plot. In this case, the marker sizes are set to [5, 10] to match the marker sizes in the plot.

related categories

gistlibby LogSnag