【问题标题】:How to get gnuplot to use a centered multi-line title, with left-aligned lines?如何让gnuplot使用居中的多行标题,左对齐的行?
【发布时间】:2013-03-11 02:22:21
【问题描述】:

我希望我的 (gnu) 图有一个多行标题。我希望标题居中(即最宽标题行的中心到边缘的距离应该相等),但不要让每行独立居中其他的,这是默认行为;我想让标题行左对齐并且仅作为一个块居中

我怎样才能做到这一点?

【问题讨论】:

    标签: alignment gnuplot title centering


    【解决方案1】:

    这有点棘手。正如 gnuplot 文档中所说:

    The `set title` command produces a plot title that is centered at the top of
    the plot.  `set title` is a special case of `set label`.
    

    虽然label 命令接受一个对齐参数,例如

    set label "mylabel" right
    

    title 没有:很难居中。我的解决方法是在标题所在的位置使用label。要创建多行,请在双引号内使用换行符 (\n)。

    set title "\n"
    set label 1 "first line\nsecond line" at graph 0.5,1.125 left
    

    虚拟的set title 命令是为了让gnuplot 调整两行标题的上边距。我发现该位置 (0.5,1.125) 很好地再现了默认标题位置。不过,这不会使标签居中于绘图的中间——它将与中心线左对齐或右对齐。解决方法是手动调整标签的 x 位置:

    set title "\n"
    shift = 0.05 # manually adjust
    set label 1 "first line\nsecond line" at graph (0.5-shift),1.125 left
    

    【讨论】:

    • ...我不能以某种方式预先计算宽度吗?
    • 近似地,使用strlen 命令,它为您提供字符串中的字符数。我猜这个方法是strlen标签的最长字符串,在字符宽度和屏幕坐标之间转换,然后移动字符串长度的一半。
    【解决方案2】:

    另一种方法是使用固定宽度的字体并使所有行的长度相同。

    set term pngcairo size 800,600 font "Courier,10" enhanced crop
    
    set title "\
    Synchronic                        \n\
    (. orange) signal columns         \n\
    (+  green) planar signal          \n\
    (.    red) paraboloid             \n\
    (x  black) intersection           \n\
    (|  black) detection              "
    

    【讨论】:

    • 这仅适用于标题吗? ...此外,强制使用等宽字体并不比必须使用非左对齐的线条好得多...
    猜你喜欢
    • 2021-04-18
    • 1970-01-01
    • 2015-07-18
    • 2022-08-21
    • 1970-01-01
    • 2015-01-16
    • 1970-01-01
    • 1970-01-01
    • 2012-01-31
    相关资源
    最近更新 更多