How do you get a legend to have different marker sizes?
8 views (last 30 days)
Show older comments
Kulan Sinclair
on 4 Jul 2018
Answered: Walter Roberson
on 4 Jul 2018
I have a set of dummy points and I am trying to make a legend with most of the markers being the same size but 3 of them being different sizes(can be based on the size of the points in the scatter plot or resized individually) list1-5 should have the same marker size and Phase A should have a larger marker size Phase B should have the normal marker size and Phase C should have a small marker size. The text should remain the same in all cases.
figure
hold on
%sets up data for the legend
list1 = scatter(NaN,NaN, 40, 'r', 'filled');
list1.MarkerEdgeColor = 'k';
list2 = scatter(NaN,NaN, 40, 'y', 'filled');
list2.MarkerEdgeColor = 'k';
list3 = scatter(NaN,NaN, 40, 'g', 'filled');
list3.MarkerEdgeColor = 'k';
list4 = scatter(NaN,NaN, 40, 'c', 'filled');
list4.MarkerEdgeColor = 'k';
list5 = scatter(NaN,NaN, 40, 'm', 'filled');
list5.MarkerEdgeColor = 'k';
list6 = scatter(NaN,NaN, 90, 'w', 'filled');
list6.MarkerEdgeColor = 'k';
list7 = scatter(NaN,NaN, 40, 'w', 'filled');
list7.MarkerEdgeColor = 'k';
list8 = scatter(NaN,NaN, 10, 'w', 'filled');
list8.MarkerEdgeColor = 'k';
lgd = legend([list1 list2 list3 list4 list5 list6 list7 list8], 'list1',...
'list2', 'list3', 'list4', 'list5', 'Phase A',...
'Phase B', 'Phase C','AutoUpdate ','Off', 'Location', 'northwest');
0 Comments
Accepted Answer
Walter Roberson
on 4 Jul 2018
Since those are all dummy scatter() calls to create the legend entries, replace them with calls to plot(), such as
list1 = plot(nan, nan, 'MarkerSize', 40, 'MarkerEdgeColor', 'k', 'MarkerFaceColor', 'r');
0 Comments
More Answers (0)
See Also
Categories
Find more on Legend in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!