How to change the symbol size of the legend

조회 수: 49 (최근 30일)
Miraboreasu
Miraboreasu 2023년 1월 27일
편집: Rik 2023년 1월 27일
figure
cmap = colormap(cool(4));
hold on
LL(1) = scatter(nan, nan,75, cmap(1,:), "square", 'filled');
hold on
LL(2) = scatter(nan, nan,75, cmap(2,:), "square", 'filled');
hold on
LL(3) = scatter(nan, nan,75, cmap(3,:), "square", 'filled');
hold on
LL(4) = scatter(nan, nan,75, cmap(4,:), "square", 'filled');
hold on
LL(5) = scatter(nan, nan,200, "black", "d");
hold on
LL(6) = scatter(nan, nan,200, "black", "o");
legend(LL, {'1', '2','3', '4','5', '6'},'Location','eastoutside')
set(gca,'fontweight','bold','FontSize',30)
Hello how to change the size (make them bigger) of the "square", "d", and "o"(in front of numbers) in the legend.

답변 (1개)

Rik
Rik 2023년 1월 27일
편집: Rik 2023년 1월 27일
This is only possible by increasing the size of the markers themselves in the plot. If you don't want that, you will need to create dummies with NaN.
Edit:
After some experimentation, I found that there is a maximum size of marker that legend will show, which is about 10. Note that the size argument for a line object (i.e. the result of plot) describes the length, while the size argument for scatter describes the area, hence the need to square to get the same visual size.
For scatter, the legend will always have the same size, while for plot the size is the same as what you see in the axis.
cmap = colormap(cool(10));
hold on
for n=1:size(cmap,1)
sz=n*2;
plot(sz, sz,'d','MarkerFaceColor',cmap(n,:),'MarkerEdgeColor', cmap(n,:), ...
'MarkerSize',sz,...
'DisplayName',sprintf('plot size=%d',sz));
scatter(sz/2, sz, sz^2, cmap(n,:), 'square', 'filled',...
'DisplayName',sprintf('scatter size=%d',sz^2))
end
hold off
axis([0 sz*1.5 0 sz+1])
legend('Location','southeast')
The end result is that you will have to create your own implementation of the legend with a second axis. That way you are no longer limited by the maximum size.
  댓글 수: 1
Miraboreasu
Miraboreasu 2023년 1월 27일
편집: Miraboreasu 2023년 1월 27일
LL(1) = scatter(nan, nan,75, cmap(1,:), "square", 'filled');
Thanks for the reply, but I have this as dummy with nan, and size 75, when I change 75 to 100, the size of the markers won't change @Rik

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

카테고리

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