Gnuplot中第一个和后续绘图之间的行距变化

Gnuplot中第一个和后续绘图之间的行距变化,gnuplot,Gnuplot,如果在一系列绘图中使用相同的标签(字体不同于绘图的字体),则第一个绘图中的行距似乎遵循绘图的字体,即,它比其余绘图中的行距大得多或小得多: 设置关键点间距对该行为没有影响。如果标签和打印字体相同,则不会发生这种情况 如何避免这种情况 下面是生成上述图的最短代码: set terminal png size 200,200 set label "1st line\n2nd line" font "monospace, 8" set output "1.png" p

如果在一系列绘图中使用相同的标签(字体不同于绘图的字体),则第一个绘图中的行距似乎遵循绘图的字体,即,它比其余绘图中的行距大得多或小得多:

设置关键点间距对该行为没有影响。如果标签和打印字体相同,则不会发生这种情况

如何避免这种情况

下面是生成上述图的最短代码:

    set terminal png size 200,200
    set label "1st line\n2nd line" font "monospace, 8"
    set output "1.png"
    plot x
    set output "2.png"
    plot x

在Linux下使用了Gnuplot 5.2 patchlevel 6。

这确实是一种奇怪的行为。对我来说,这看起来像是一个初始化错误。 如果我从gnuplot命令行启动代码,它只会第一次发生。如果再次打印,则行间距似乎是正确的。 那么,如何避免这种情况呢?画两次!我同意,这不是一个真正令人满意的解决方案,必须有更好的解决方案

代码:

reset session

set terminal png size 200,200

set label 1 "1st line\n2nd line" font "monospace, 8"
set output "1.png"
plot x
set output "1.png"
plot x

set output "2.png"
plot x
set output
reset session

set terminal png size 200,200 font "monospace, 8"

set label 1 "1st line\n2nd line"
set xtics font "Arial, 12"
set ytics font "Arial, 12"
set key font "Arial, 12"
set output "1.png"
plot x

set output "2.png"
plot x
set output
添加:

reset session

set terminal png size 200,200

set label 1 "1st line\n2nd line" font "monospace, 8"
set output "1.png"
plot x
set output "1.png"
plot x

set output "2.png"
plot x
set output
reset session

set terminal png size 200,200 font "monospace, 8"

set label 1 "1st line\n2nd line"
set xtics font "Arial, 12"
set ytics font "Arial, 12"
set key font "Arial, 12"
set output "1.png"
plot x

set output "2.png"
plot x
set output
另一种解决方法可能是如下。将
monospace,8
设置为终端的默认值。然后调整所有其他标签的字体,如
xtics
xlabel
ytics
ylabel

代码:

reset session

set terminal png size 200,200

set label 1 "1st line\n2nd line" font "monospace, 8"
set output "1.png"
plot x
set output "1.png"
plot x

set output "2.png"
plot x
set output
reset session

set terminal png size 200,200 font "monospace, 8"

set label 1 "1st line\n2nd line"
set xtics font "Arial, 12"
set ytics font "Arial, 12"
set key font "Arial, 12"
set output "1.png"
plot x

set output "2.png"
plot x
set output
结果:

reset session

set terminal png size 200,200

set label 1 "1st line\n2nd line" font "monospace, 8"
set output "1.png"
plot x
set output "1.png"
plot x

set output "2.png"
plot x
set output
reset session

set terminal png size 200,200 font "monospace, 8"

set label 1 "1st line\n2nd line"
set xtics font "Arial, 12"
set ytics font "Arial, 12"
set key font "Arial, 12"
set output "1.png"
plot x

set output "2.png"
plot x
set output

正如伊桑在评论中指出的那样:


这是一个特定于基于libgd的终端(png-jpeg-gif)的错误。您可以选择
set term pngcairo
来避免它

这个bug已经存在了

已在5.2.8中修复,将于本月底[2019年11月]发布


好吧,既然问题是如何避免,这是一个显而易见的答案,而不是“发生了什么事?”你至少要经历一下麻烦来解决这个问题。@DanSp。我现在发布了@theozh,我这样做了,但在我的(真实)应用程序中,它甚至比最小的示例更令人不满意,因为绘图是由for循环在自动生成的数据文件列表上创建的。这是一个特定于基于libgd的终端(png-jpeg-gif)的错误。你可以选择
set term pngcairo
来避免它。谢谢@Ethan,你想把它写在答案中吗?通常我用的是pngcairo,我不知道为什么这次忘了。