How to make marker size bigger in legend for scatter plot?
84 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
How to make marker size bigger in legend for scatter plot?
I want the marker size in legend same as in scatter plot. But by default the legend markers are too small.
Attching the figure for the refernce.![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1349849/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1349849/image.png)
0 Commenti
Risposte (1)
Walter Roberson
il 8 Apr 2023
In order to do this, you might need to use the undocumented second output of legend(). When you call legend() with multiple outputs, then legend() changes how it works internally, going back to an older representation. The second output becomes graphic handles that you can manipulate independently of the markers on the main plot.
2 Commenti
Mahdi Nobar
il 10 Set 2023
but there is no graphics of type line to change the marker size!! please clarify more it does not work.
Walter Roberson
il 10 Set 2023
h = plot(1:5, 2:6, 'k*-', 1:5, 6:-1:2, 'r.')
[out1, out2] = legend({'first', 'second'})
h(1).MarkerSize = 10; %first line
%second output of legend has
%* one text() entry per handle
%* followed by pairs with
% * one line() per line() handle to draw the sample line
% * one line() per line() handle to draw the sample marker
offset_to_lines = length(h); %one text per handle
offset_to_legend_line = 1;
offset_to_legend_marker = 2;
line_index_to_change = 1;
idx = offset_to_lines + (line_index_to_change - 1) * 2 + offset_to_legend_marker
out2(idx).MarkerSize = 15;
You can see here that although the marker size for the first line is set to 10, that the marker size in the legend has been set to 15.
Vedere anche
Categorie
Scopri di più su Legend in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!