【问题标题】:Label text truncated after increasing font size增加字体大小后标签文本被截断
【发布时间】:2017-08-31 17:57:34
【问题描述】:

我按照this question 中的步骤进行操作,并尝试将单个文本对象设置为更大的字体。这是我的示例代码:

hf = figure;
set(hf, 'DefaultAxesFontSize', 14)
hx = axes('Parent',hf);
[hx,hp1,hp2] = plotyy(hx, rand(10,1),rand(10,1),rand(10,1),rand(10,1),'scatter');
hlx = xlabel(hx(1), 'Only half of this line show up');
hl1 = ylabel(hx(1), 'Not usually truncated but less border');
hl2 = ylabel(hx(2), 'Only part of this line show up');
ht  = title(hx(1), 'Too close to border');

如图所示,标签被图形的边框截断。我必须将图形拖到非常大 - 与预期相反 - 以显示所有文本。

如何根据文本字体大小自动设置文本框,这样即使是小图也不会被剪切?

我知道我可以通过设置轴的Position 来手动完成,但它是一种手动和猜测和尝试的方式。有没有自动计算利润的方法?

【问题讨论】:

    标签: matlab matlab-figure


    【解决方案1】:

    可以做的一件事是根据新的文本字体大小计算增加的​​边距。假设我们知道 Matlab 的默认字体大小为 10,否则通过get(hf,'DefaultAxesFontSize') 获取。

    然后通过get(hx, 'Position')得到坐标轴的相对位置,给出四个百分比值。前两个定义左边距和下边距。由于它是用于标签的,将字体大小从 10 增加到 14 意味着文本框应该增长 1.4 倍。接下来的两个数字定义了轴的大小。由于两边的文本框都增长了 1.4 倍,假设原始大小为 x,那么新大小为 1-[(1-x)*1.4] = 1.4x - 0.4。

    建议的解决方法:

    hf = figure;
    set(hf, 'DefaultAxesFontSize', 14)
    hx = axes('Parent',hf);
    set(hx, 'Position', [1.4 1.4 1.4 1.4].*get(hx, 'Position')+ [0 0 -.4 -.4])
    [hx,hp1,hp2] = plotyy(hx, rand(10,1),rand(10,1),rand(10,1),rand(10,1),'scatter');
    hlx = xlabel(hx(1), 'Only half of this line show up');
    hl1 = ylabel(hx(1), 'Not usually truncated but less border');
    hl2 = ylabel(hx(2), 'Only part of this line show up');
    ht  = title(hx(1), 'Too close to border');
    

    您可以将手动输入的数字1.4 替换为新分配的(希望更大)字体大小与原始大小之间的比率 10。

    【讨论】:

      猜你喜欢
      • 2013-03-02
      • 2012-12-21
      • 2019-03-24
      • 2012-07-05
      • 1970-01-01
      • 2012-11-25
      • 2016-01-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多