How to change the symbol size of the legend
61 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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.
0 comentarios
Respuestas (1)
Rik
el 27 de En. de 2023
Editada: Rik
el 27 de En. de 2023
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 comentario
Ver también
Categorías
Más información sobre Legend en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!