How to make marker size bigger in legend for scatter plot?

조회 수: 83 (최근 30일)
Sahil Wani
Sahil Wani 2023년 4월 8일
댓글: Walter Roberson 2023년 9월 10일
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.

답변 (1개)

Walter Roberson
Walter Roberson 2023년 4월 8일
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
Mahdi Nobar
Mahdi Nobar 2023년 9월 10일
but there is no graphics of type line to change the marker size!! please clarify more it does not work.
Walter Roberson
Walter Roberson 2023년 9월 10일
h = plot(1:5, 2:6, 'k*-', 1:5, 6:-1:2, 'r.')
h =
2×1 Line array: Line Line
[out1, out2] = legend({'first', 'second'})
out1 =
Legend (first, second) with properties: String: {'first' 'second'} Location: 'northeast' Orientation: 'vertical' FontSize: 9 Position: [0.7171 0.8210 0.1685 0.0797] Units: 'normalized' Show all properties
out2 =
6×1 graphics array: Text (first) Text (second) Line (first) Line (first) Line (second) Line (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
idx = 4
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Legend에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by