Strange behaviour in gnuplot for label with Arial font face in pdfcairo terminal - gnuplot

I am obtaining a strange behaviour on gnuplot 5.2.2 pdfcairo terminal with a label composed of several lines and attempted to be printed align to center. The label is the signature for my plots, it is composed of my name (first line), my institution (second line) and the date, obtained from time(0) and strftime.
In a multiplot script I noticed that the date (3rd line) was printed align to left while the other two line were printed align to center as intended. Then I placed the set label instruction before the first plot was called so that the label is printed two times. Then, in the first call, date was aligned to left but in the second call the date was aligned to center, as intended. Same happens if the align to right mode is intended. However if the strftime string is substituted by a regular string "foo" then alignment works fine.
This behaviour only happens if font is set to Arial and if the terminal is set to pdfcairo. If font is set to Ubuntu (or Times) or if the terminal is set to pngcairo then all calls print the label truly align to center.
A minimal workable example is:
set terminal pdfcairo enhanced color font "Arial,"
set output "prueba.pdf"
set multiplot layout 1,2
set colors podo
Cadena_firma="Martin-Olalla JM\nUniversidad de Sevilla\n".strftime("%Y/%m/%d",time(0))
set label 1 at screen 0.85,0.25 Cadena_firma noenhanced center font "Arial,10" tc rgb '#9d2235' front
set yrange [-2:2]
plot sin(x) lc 3
plot cos(x) lc 3
I attached the output, highlighting the weird printing of the date.
This is only happening in one of the computers I handle. It is easily solvable by changing the font. Nonetheless I am curious and it might be interesting for others.

There have been multiple reports of font problems that all appear to trace back to bad pango/cairo library versions. Some of the problems are OS-specific and some are font-specific. So there are probably multiple issues involved. Here are some tracker items:
https://gitlab.gnome.org/GNOME/pango/issues/422
and
https://sourceforge.net/p/gnuplot/bugs/2052/

Related

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:
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.
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:
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].

How to place labels on top of the margin?

I am using gnuplot with epslatex terminal. I want to know how to put the
label on top of a margin, so that the part of margin under the label is invisible. In the figure I attached, the part of margin under the label
is still visible.
In principle you should be able to tell gnuplot to put your text labels into a box by using the set label ... front boxed, and the specify that the box should be opaque and white using something like set style textbox opaque noborder fillcolor rgb "white". However, this is not supported by all terminals, and epslatex seems to be one of those where this doesn't work.
However, in epslatex you can simply use latex commands to create a white background box around your label text:
set term epslatex standalone
set outp "test.tex"
set label "\\colorbox{white}{This is a label}" at 6.,0.5 front
plot sin(x)
set output
gives

Gnuplot Expand Plot to Fill Area

I am making a video for my simulation, where each each frame is a picture of the simulation, and a graph. I'm making the graph with gnuplot, and I first run the simulation to determine the x and y ranges to use and then hardcode the range into the plot script. It works okay, but the plot does not use up the entire surface, there is a ton of white space, and the plot is only about 1/4 of the total area. Is there a way to make the plot expand closer to the edges of the boundary, or a way to control the plot placement?
Script:
set term postscript eps color enhanced "Helvetica" 36
set output 'image.eps'
set size ratio 0.8
set logscale x
set xlabel 'Time(Arb. Units)'
set xrange [10:100000]
set yrange [0:1.6]
set y2range [0:0.5]
set ylabel 'Absorption(%)'
set y2label 'Emission'
set format x '%.0e'
set xtics 10, 100, 100000
set key noautotitles
plot 'absorption.dat' axes x1y1 w lines lt 3 lw 5, 'emission.dat' axes x1y2 w lines lt 1 lw 5
Here is what comes out:
I set a grey background so you can see what space is being wasted.
Edit: I've also tried the png terminal, but that seems to make the problem even worse. The plot is shrunk even further. I replaced the top two lines of the script with:
set term png font Helvetica 36
set output 'image.png'
Then this is what comes out:
There are several things involved in the computation of the plot size:
Different terminals have different default canvas sizes. If the defaults don't fit your needs, change the size set terminal ... size ...
The canvas has a fixed aspect ratio (given by the terminals size settings) and you impose an additional constraint with set size ratio... which affects only the plot but not the canvas size. So, if you need this size ratio you must adapt the plot canvas to it.
A third parameter are the margins. Since gnuplot don't exactly know how the labels will be rendered by the terminal, the margins cannot be exact. You can set margins manually with set bmargin ... (for the bottom margin) and equivalently for the other margins.
I would suggest to use a terminal that accept the crop flag
e.g. png, gif, jpeg but also epscairo

Gnuplot Postscript Special Characters Math Equation

I`d like to write the math stuff into a plot using gnuplot 5:
I am using the terminal postscript enhanced because as far as I know this terminal is the only only capable of doing such things.
I used this code:
set label 1 at 400,200 '{/Symbol=50\362#_{/=15 350}^{/=15\154}}' front
This gets me everything except the subscribed averageunder the lambda symbol.
I tried everything with {,}and so on but I think I missing the part where I can escape the /SymbolStyle.
Many terminals support enhanced text, not only the postscript terminal.
In order to use another font than /Symbol for the subscript you could change the font explicitely to a different one for this. However, a better approach is to change the nesting so that /Symbol affects only two parts:
set label 1 at 0,0 '{/=50{/Symbol \362}#_{/=15 350}^{/=15{/Symbol \154}_{/=10 average}}' front
plot x
Output with gnuplot 5.0 with wxt is
If you're using the postscript terminal anyway, you could give a try to the epslatex terminal (or cairolatex):
set terminal epslatex standalone color colortext
set output 'equation.tex'
set label 1 at -5,5 '$\displaystyle\int_{350}^{\lambda_{\mathrm{average}}}$'
plot x
set output
system('latex equation.tex')
system('dvips equation.dvi')
system('ps2pdf equation.ps')

How to make plots larger in GnuPlot

I am generating mapped 3D plots using the following config file (XRANGE and YRANGE are set later)
#!/usr/bin/gnuplot
reset
set term postscript eps enhanced
set size square
set xlabel "X position"
set ylabel "Y position"
#Have a gradient of colors from blue (low) to red (high)
set pm3d map
set palette rgbformulae 22,13,-31
set xrange [0 : XRANGE]
set yrange [0 : YRANGE]
set style line 1 lw 1
unset key
set dgrid3d 45,45
set hidden3d
splot "data.data" u 1:2:3
The resulting image looks something like this
Note: I have converted to jpg so the quality is lower, and I have placed a border around the image.
A great deal of space is wasted above and below. This is not a problem until I embed the image into a LaTex document, at which point it will look like so (again, pdf document converted to jpg image)
The image on the right is also created with GnuPlot, but it is slightly larger (as is evident by looking at the border I have drawn around the top two images). The reason for this is because GnuPlot pads the 3D plot with top and bottom white space. How can I remove this without having to manually edit all 50+ plots I have?
There are two solutions to this, one is unreliable, the other is a hack.
Using GnuPlot, the margin settings can be used to specify distances from the appropriate margins. For example, setting lmargin 0 and bmargin 0 essentially pushes the axes off the page. Similar values can be assigned to the tmargin and rmargin to stretch the graph. Although this worked for 2D graphs, it did not work for 3D graphs (I suspect this has to do with the fact that I set the graph to be a square).
When graphs are set to be of square size, Gnuplot still calculates for the entire screen. The eps file can be manipulated directly to change this by looking for a line like so %%BoundingBox: 50 50 410 302 and changing 410 to something smaller. Alternatively, and this is what I did, you can run eps2eps in.eps out.eps and it will crop it for you. Just make sure in.eps is not the same file as out.eps or it won't work.
I also crop the Bounding Box afterwards, since I hate playing around with margins in gnuplot. I realized that somehow, eps2eps indeed does adjust the bounding box, but it also transforms text (labels etc) into pixel-graphic?!
I usually use "epstool" which conserves text as text when croping the bb, the command I use is:
epstool --copy --bbox in.eps out.eps
Use the <scale> argument in set view, this will magnify the plot without changing text size or title position.
In your case, because you use the map view, you need:
set view 180,0,1.5
where 180,0 is equivalent to map view and 1.5 is the scaling factor.

Resources