Matlab:减少图例中符号和标签之间的间距

Matlab:减少图例中符号和标签之间的间距,matlab,legend,matlab-figure,legend-properties,Matlab,Legend,Matlab Figure,Legend Properties,在matlab中使用图例命令时,如何减少图例符号与其相应标签之间的水平距离 示例代码: Line1=plot(x1,y1,'s'); Line2=plot(x2,y2,'o'); Line3=plot(x3,y3,'^'); Leg=legend([Line1, Line2, Line3],... 'Line1 text','Line2 text','Line3 text',... 'Location','NorthEast'); 我很好奇您为什么要

在matlab中使用图例命令时,如何减少图例符号与其相应标签之间的水平距离

示例代码:

Line1=plot(x1,y1,'s');
Line2=plot(x2,y2,'o');
Line3=plot(x3,y3,'^');
Leg=legend([Line1, Line2, Line3],...
           'Line1 text','Line2 text','Line3 text',...
           'Location','NorthEast');

我很好奇您为什么要这样做,但可能的解决方案是:

clf;
hold on;
x=0:0.1:2*pi;
plot(x,sin(x),'s');
plot(x,cos(x),'o');
ax=legend('sin','cos');
LEG = findobj(ax,'type','text');
set(LEG,'HorizontalAlignment','center')

您可以测试
'center'
'right'
并使用任何有效的方法。如果两者都不起作用,请忽略我的答案。

您可以找到
Leg
的子项,搜索其
类型设置为
text
的子项并重新定位它们。下面是一个代码来演示如何做到这一点。它将它们向左移动0.2(相对于图例框)

ch = get(Leg, 'Children');
textCh = ch(strcmp(get(ch, 'Type'), 'text'));
for iText = 1:numel(textCh)
    set(textCh(iText), 'Position', get(textCh(iText), 'Position') + [-0.2 0 0])
end

谢谢,好主意,但这会导致图例文本与符号重叠。我只是想提高我的情节的可读性,我觉得就像现在一样,图例文本和符号之间的空间太大了。谢谢!这正是我想做的。