stafusa
stafusa

Reputation: 195

Line spacing changing between 1st and following plots in Gnuplot

If the same label (in a font different than that of the plot) is used in a series of plots, the line spacing in the first of them seems to follow the plot's font, i.e., it's considerably larger or smaller than in the remaining plots:

1st plot2nd plot

Setting the key spacing has no influence on this behavior. And this doesn't happen when label and plot fonts are the same.

How can that be avoided?

Here's a minimal code that produces the plots above:

    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

Gnuplot 5.2 patchlevel 6, under Linux, was used.

Upvotes: 1

Views: 352

Answers (2)

stafusa
stafusa

Reputation: 195

As Ethan pointed out in comments:

It is a bug that is specific to the libgd-based terminals (png jpeg gif). You can avoid it by choosing set term pngcairo instead.

The bug has been reported and is already

Fixed in 5.2.8, which will be released by the end the month [Nov 2019].

Upvotes: 0

theozh
theozh

Reputation: 26200

This is indeed a strange behaviour. To me this looks like an initialization bug. If I start the code from the gnuplot command line, it happens only the first time. If you plot again, the line spacing seems to be the correct one. So, how can this be avoided? Plot it twice! I agree, this is not a really satisfying solution, there must be better ones.

Code:

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

Addition:

Another possibility to workaround might be the following. Set monospace,8 as default for the terminal. But then adjust the font of all other labels like xtics, xlabel, ytics, ylabel, key, ...

Code:

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

Result:

enter image description here

Upvotes: 1

Related Questions