如何在使用matlab进行绘图时使图例中的标记变小

问题描述 投票:0回答:1

在此图中,图例中的标记太大,我该如何缩短标记。

我花了大量时间在网上搜索解决方案。但是我没有找到任何可以解决此问题的解决方案。

谢谢。

enter image description here

这是代码,

latency = [1 1.3 0.5;...
           0.8 1.2 0.4;...
           0.7 1.1 0.35;...
           0.9 1.0 0.3;...
           0.8 1.2 0.4;...
           0.7 1.1 0.3];
h = bar(latency);
set(h(1), 'FaceColor',[33 36 61]./255)
set(h(2), 'FaceColor',[240 240 240]./255)
set(h(3), 'FaceColor',[250 128 114]./255)
set(h, 'LineWidth', 1);
set(gca,'Linewidth',1,'Fontname', 'arial');
set(gca, 'XLim', [0, size(latency,1)+1])
set(gca, 'YLim', [0 max(max(latency))*1.1]);
xlabel('(a) Latency','FontSize',14)
ylabel('Latency (us)','FontSize',14)
legend({'AAAAAAAA', 'BBBBBBBB', 'CCCCCCCC'}, 'Orientation', 'horizontal','FontSize',11)
box on;

更新:

根据答案,我添加两行代码:

[lgd,icons,plots,txt] = legend({'AAAAAAAA', 'BBBBBBBB', 'CCCCCCCC'});
icons(4).Children.XData = icons(4).Children.XData/2;

现在我得到了这个图例。

但是文本前有一个空格。

enter image description here

matlab matlab-figure figure
1个回答
0
投票

有一个undocumented属性ItemTokenSize来做到这一点:

% Fixe the new size of each box:
box_size = [10 10 10]

% Get the handle
hdl = legend({'AAA', 'BBB', 'CCC'})

% Set the new size
hdl.ItemTokenSize = box_size;

% Then recenter the legend
% ...

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.