【发布时间】:2013-03-11 02:22:21
【问题描述】:
我希望我的 (gnu) 图有一个多行标题。我希望标题居中(即最宽标题行的中心到边缘的距离应该相等),但不要让每行独立居中其他的,这是默认行为;我想让标题行左对齐并且仅作为一个块居中。
我怎样才能做到这一点?
【问题讨论】:
标签: alignment gnuplot title centering
我希望我的 (gnu) 图有一个多行标题。我希望标题居中(即最宽标题行的中心到边缘的距离应该相等),但不要让每行独立居中其他的,这是默认行为;我想让标题行左对齐并且仅作为一个块居中。
我怎样才能做到这一点?
【问题讨论】:
标签: alignment gnuplot title centering
这有点棘手。正如 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标签的最长字符串,在字符宽度和屏幕坐标之间转换,然后移动字符串长度的一半。
另一种方法是使用固定宽度的字体并使所有行的长度相同。
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 "
【讨论】: