how to decrease the size of the legend in a figure
Mostrar comentarios más antiguos
The following code plots a figure. I want to remove the space within the legend. I spend one day to try to solve this problem. However, I failed. Would you like to help me.
x = 0:0.5:10;
figure; hold on;
plot(x,sin(x), 'Marker', 'o');
plot(x,cos(x), 'Marker', 's');
[leg, objs] = legend({'sin', 'cos'}, 'Location', 'SouthWest');
line_start_end = [0.01, 0.4];
line_text_step = 0.01;
% for each line, text object, adjust their position in legend
for i = 1:numel(objs)
if strcmp(get(objs(i), 'Type'), 'line')
% line object
if 2 == numel(get(objs(i), 'XData')) % line
set(objs(i), 'XData', line_start_end);
else % marker on line
set(objs(i), 'XData', sum(line_start_end)/2);
end
else
%text object
text_pos = get(objs(i), 'Position');
text_pos(1) = line_start_end(2) + line_text_step;
set(objs(i), 'Position', text_pos);
end
end
see the following result.

What I want is :

Respuesta aceptada
Más respuestas (1)
KSSV
el 16 de Nov. de 2017
plot(rand(4))
lgd = legend('One','Two','Three','Four');
lgd.FontSize = 24;
Categorías
Más información sobre Legend en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!