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].
Related
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/
I need to write one of my axis label as $\langle\alpha\rangle$. I don't know how to get this Dirac notation in gnuplot. Can someone help.
One solution might be to use Gnuplot as a "pre-processing" tool in order to generate a template which is then compiled with LaTeX. To this end, consider for example following Gnuplot script:
set terminal lua tikz size 8cm,6cm clip background rgb '#ffffff'
set output 'frame.tex'
set xr [0:10]
set yr [0:10]
set xtics out nomirror
set ytics out nomirror
set key bottom right reverse spacing 2 width 2
set xlabel '$\langle\alpha\rangle$'
set ylabel '$f(\langle\alpha\rangle)$'
plot x t '$f(\langle\alpha\rangle)$'
When supplied to Gnuplot, it produces a file frame.tex. However, this is not a standalone LaTeX document, just the plot itself rendered with the famous TikZ package. Nevertheless, it is rather straightforward to embed it in a document as:
\documentclass[aip,jcp,reprint,amsmath,12pt]{revtex4-1}
\usepackage[utf8]{inputenc}
\usepackage[margin=0pt,papersize={8cm,6cm},headheight=0pt]{geometry}
\usepackage{graphicx}
\usepackage{tikz, fp, scalefnt, ifthen}
\usepackage{gnuplot-lua-tikz}
\usepgflibrary{fixedpointarithmetic}
\pagestyle{empty}
\setlength{\fboxsep}{0pt}
\setlength{\parskip}{0pt}
\setlength{\parindent}{0pt}
\begin{document}
\begin{widetext}
\input{frame.tex}%
\end{widetext}
\end{document}
If this file is called for example figure.tex, then pdflatex figure.tex produces:
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
When I input the following into the gnuplot window:
set xlabel "x"; set ylabel "y";
plot "rk1000.dat" with lines, "teor1000.dat" with lines
The result is a nice plot. However, when I attempt to save it as a .png file, the result is not so nice. After typing
set xlabel "x"; set ylabel "y"; set terminal png size 800,600;
plot "rk1000.dat" with lines, "teor1000.dat" with lines
the result is gnuplot spitting out garbage characters and doing nothing. Here's a screenshot:
How do I fix this? Not even an hour ago I had no problem saving my plots.
You can use set output in your script to make gnuplot redirect the output to a file:
set terminal png size 800,600
set output "plot.png"
plot "rk1000.dat" with lines, "teor1000.dat" with lines
If you are creating png images using gnuplot, the "pngcairo" terminal produces better-looking results. Try set terminal to see the list of available terminals.
Just save the output to a png file:
gnuplot script.gp > picture.png
Search the web for "redirection" if you want to know more.
you should plot first then set term
ex
"plot '../log/test_coverage_${atpg_mode}.log.tmp' title 'Ori ATPG' w lp lt 3 pt 9"
"set terminal png font \"/usr/share/fonts/liberation/LiberationSerif-Italic.ttf\" 9" ; # save the image as the png format
"set terminal png size 1000, 800" ; # save the image size as 800*1000
"set output '${REPORT_DIR}/Test_Coverage_Curve_${atpg_mode}.png'"
"replot"
I decided to migrate to the latest version of gnuplot from 4.4 to 4.6
I am having issue with the x label disappearing with version 4.6 but being there with version 4.4.
here is a stripped down version of my script.
set key outside
set title "MY TITLE"
set timefmt "%m/%d/%Y-%H:%M:%S"
set format x "%m/%d %H:%M"
set xdata time
set ylabel "Y LABEL"
set xlabel "Time"
set grid
set xtics rotate by 90 offset 0,-5
set terminal pngcairo size 1000,500 font ",9"
set xtics font ",8.0"
set ytics font ",8.0"
set output 'test.png'
plot '-' using 1:2 with linespoints ti "legend"
01/01/2013-00:15 186557
01/01/2013-01:15 254654
01/01/2013-04:00 180146
01/01/2013-06:15 191059
e
set key inside
I've identified the issue to this line
set xtics rotate by 90 offset 0,-5
Because my label is too long the offset makes it go away
if you remove the offset to
set xtics rotate by 90
Not the label show but in the middle of the chart.
Version 4.4 used to compress the chart to leave room for the label.
I guess my knowledge to gnuplot is limited.
Anyone has an idea?
thanks
UPDATED ANSWER, courtesy of Ethan Merritt
A better way to do this is to change the justification of the labels to being right justified (rather than the default centered).
set xtics rotate by 90 right
This correctly calculates the margin without needing to hardcode a margin size
The label placement here seems a little flaky to me. I think there might be a bug which I'll probably report. One workaround is to explicitly set the location of the "x-axis" via:
set bmargin at screen 0.2
The reason it seems flakey is because with set bmargin at screen 0.2, the xtic labels clearly extend higher than the position of the xlabel. However, if you comment that line out, all of a sudden they don't extend higher than the position of the xlabel.
Here are the plots with and without that line:
Perhaps cairo/pango cut out labels where any portion of the label extends past the visible "canvas" area?
As a side note, the plot also seems to be roughly correct if I use the postscript terminal...