How to change the symbol size of the legend

35 ビュー (過去 30 日間)
Miraboreasu 2023 年 1 月 27 日
編集済み: Rik 2023 年 1 月 27 日
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')
Hello how to change the size (make them bigger) of the "square", "d", and "o"(in front of numbers) in the legend.

回答 (1 件)

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.
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)
plot(sz, sz,'d','MarkerFaceColor',cmap(n,:),'MarkerEdgeColor', cmap(n,:), ...
'DisplayName',sprintf('plot size=%d',sz));
scatter(sz/2, sz, sz^2, cmap(n,:), 'square', 'filled',...
'DisplayName',sprintf('scatter size=%d',sz^2))
hold off
axis([0 sz*1.5 0 sz+1])
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 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 Center および File ExchangeLegend についてさらに検索





Community Treasure Hunt

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

Start Hunting!

Translated by