Gnuplot multiplot positions all text incorrectly in epslatex terminal - latex

I am trying to use the multiplot feature of gnuplot to make a inset graphic on the main plot. I can generate the plot exactly as I want with term='wxt' except for the axis labels, which require LaTeX formatting for generating the desired symbols. When I submit the same commands to term='epslatex', the plot is fine, but all text (axis and tic mark labels) is positioned incorrectly.
I thought using the set size & origin commands might have confused the epslatex terminal output, so I attempted to use the layout command and make the plots side by side just to see if the text would print correctly. It did not.
I'm using gnuplot 4.6 patch 4, and Linux Mint 17.
My script is below. The commented sections indicate the original script that used set size and origin commands to manually place the second plot as a inset, rather than side by side.
set term epslatex color font ",16"
unset key
set termoption dash
set style line 1 lc rgb 'blue' lw 2 lt 1
set style line 2 lc rgb 'red' lw 2 lt 3
set style line 3 lc rgb 'green' lw 2 lt 5
set style line 4 lc rgb 'magenta' lw 2 lt 7
set style line 5 lc rgb 'black' lw 1 lt 0
set output "gr-thresholds.tex"
#set size 1,1
# set multiplot
set multiplot layout 1,2
# bigger plot
set autoscale
set ytics scale default autofreq
set xrange[0:14]
set yrange[0:1.7]
set xlabel 'r (\AA)'
set ylabel '$g(r)$'
#set size 1,1
#set origin 0,0
plot "foo1.csv" w l ls 2, \
"foo2.csv" w l ls 3 , \
"foo3.csv" w l ls 1, \
"foo4.csv" w l ls 4
#small inset
#set size 0.4, 0.4
#set origin 0.5,0.15
set xrange[1.2:2.2]
set yrange[0:0.8]
set ytics 0, 0.2, 2
set xlabel ""
set ylabel ""
plot "foo1.csv" w l ls 2, \
"foo2.csv" w l ls 3 , \
"foo3.csv" w l ls 1, \
"foo4.csv" w l ls 4
unset multiplot
set output
The figure that was generated:

It might be a problem with the way you generate a pdf. The two commands dvipdfm and dvipdf produce different outcomes.
If I take your code, but plot sin(x) instead, and use the following in the terminal:
$ latex file.tex
$ dvipdfm file.dvi
I also get a mismatch between the axes and the plots.
If I use dvipdf however everything looks fine:
$ dvipdf file.dvi

Ok,
Per Tom Fenech's suggestion, I made a minimum code sample to reproduce the error, and the issue that arose is a machine state problem. To generate my graphs, I had run the script twice, once using term wxt and then again using term epslatex.
The problem is that somewhere the state of the gnuplot environment is changed and is not reset by this script. Specifically, the first time through, the default placement of the text labels is fine. The second time through, the range and labels are still attached to the size and origin from the last plot, which is the inset. I thought this was due to the order of the commands set origin/size relative to x/ylabel and x/y range, but simply running the below code twice without restarting gnuplot will generate two different plots. The first time is exactly what I wanted, the second time will skew the labels as shown above.
So I have a "solution", but it is fragile. I would appreciate if someone could explain what I need to do to make this script run multiple times without restarting each time.
Cheers,
--Jim
set term epslatex color font ",16"
unset key
f(x) = sin(x)
set output "sin.tex"
set multiplot
set size 1,1
set origin 0,0
set xrange[0:14]
set yrange[0:6]
set xlabel 'r (\AA)'
set ylabel '$g(r)$'
plot f(x)
#small inset
set size 0.4, 0.4
set origin 0.5,0.15
set xrange[1:3]
set yrange[0:4]
set ytics 0, 0.2, 2
set xlabel ""
set ylabel ""
plot f(x)
unset multiplot
set output

Related

How to generate subsrcipt in formula with text format in gnuplot, with esplatex terminal?

I have tried with the following code:
set term epslatex size 1.3, 1.3 standalone color colortext 9
set output "./test.tex"
set size square 1.3, 1.3
set xtics 1
set style line 1 lt 2 lc rgb "#470024" lw 3
#plot
set yrange [0: 1]
set xrange [0: 5]
set ytics 0.2
set border 1+2+4+8
set ylabel '$y_{\rm wait}$' offset 0.8,0,0
set xlabel '$t$' offset 0,0.5,0
plot exp(-(x)**0.3) w l ls 1 lw 3 notitle
set output
The current output.
The expected ylabel: the subscript is a normal text, instead of an italic form.
(the following part is added 2 days later)
Thanks to your help, I updated the code:
set term epslatex size 1.3, 1.3 standalone color colortext 8
set output "./text.tex"
set size square 1.5, 1.3
set xtics 1
set style line 1 lt 2 lc rgb "#470024" lw 3
#plot
set yrange [0: 1]
set xrange [0: 5]
set ytics 1
set border 1+2+4+8
set ylabel '$y_\textrm{wait}$' offset 0.8,0,0
set xlabel '$t$' offset 0,0.5,0
plot exp(-(x)**0.3) w l ls 1 lw 3 title "$N_\textrm{wait}$"
set output
Now the ylabel is exactly what I want, but I can not obtain the correct subscript for the legend.
This is not an issue with gnuplot, it is an issue with using the deprecated \rm with a modern LaTeX. Use instead \textup or \textrm. For a more complete discussion, see https://tex.stackexchange.com/questions/151897/always-textrm-never-rm-a-counterexample
gnuplot command:
set ylabel '$y_{\textup {wait}}$' offset 0.8,0,0
Edit
If the example below does not work for you then we'll need more information - gnuplot version, latex version, etc
set term epslatex standalone
set out 'font.tex'
set yrange [0: 1]
set xrange [0: 5]
set ytics 0.2
set border 1+2+4+8
set ylabel '$y_{\textrm {wait}}$' offset 0.8,0,0
set xlabel '$t$' offset 0,0.5,0
plot exp(-(x)**0.3) w l ls 1 lw 3 title '$Math_{\textup {Roman}}$'

time series plot clustered over days

I am trying to plot aircraft methane observations which are averaged in minutes. When I tried to plot it in gnuplot, several data points are clustered vertically on the day (while the data is recorded in minutes). It means that the data is plotted in steps of days, not in minutes. I was not able to fix it. I attach the simple code I used.
set terminal png size 5000,3500 enhanced font 'arial,60'
set output 'series_1.png'
set datafile separator ","
set multiplot layout 2,1
set border 31 lw 4
set grid
set xdata time
set timefmt "%Y/%m/%d/%H:%M"
set border lw 5
set xrange ["2014/09/01/00:01":"2014/11/30/00:01"]
set xtics "2014/09/01/00:01", 3600, "2014/11/30/00:01"
set yrange [1700:2500]
set format x "%d/%b/%y\n%H:%M"
set style line 2 lt -1 lw 4 pt 7 ps 3.5 lc rgb "red"
set style line 3 lt -1 lw 4 pt 7 ps 3.5 lc rgb "blue"
set size 0.8,0.6
set origin 0.1,0.2
set xlabel 'days'
set ylabel 'methane (ppb)'
plot 'data_fwd_alt.txt' using 1:($8*1e9) with linespoints ls 2 notitle
unset multiplot
My data looks like the following
2014/09/09/12:39, 26.56, 81.21,4254.11,1,000027, 1.95670000E-06, 1.89428172E-06, 6.24182808E-08
2014/09/09/12:40, 26.60, 81.24,4550.06,1,000028, 1.96390000E-06, 1.88243082E-06, 8.14691769E-08
2014/09/09/12:41, 26.65, 81.25,4728.63,1,000029, 1.94770000E-06, 1.86898377E-06, 7.87162278E-08
Any help would be very much appreciated.
Thank you all in advance.
Janardanan
Output:

Remove unnecessary margin in epslatex/gnuplot

I would like to remove unnecessary margins (gray part in the figure below) in a PDF figure generated by epslatex (gnuplot).
Following are scripts and commands to create the figure.
set term epslatex standalone
set output "figure.tex"
set xlabel "\\LARGE $x$"
set ylabel "\\LARGE $y$"
set format x "\\Large{%.1f}"
set format y "\\Large{%.1f}"
set key left top Left
set size square
set xrange [0.0:1.0]
set yrange [0.0:1.0]
plot x with lines dt 1 lw 5.0 lc rgb "red" title "\\Large $y = x$",\
x*x with lines dt 2 lw 5.0 lc rgb "green" title "\\Large $y = x^2$",\
x*x*x with lines dt 3 lw 5.0 lc rgb "blue" title "\\Large $y = x^3$"
and commands
$ gnuplot sample.gp
$ pdflatex figure.tex
Instead of pdflatex, xelatex would also work. I would like to directly convert to PDF file.
It will be super good if we can remove these margins without too much effort (such as removing the margin manually one-by-one).
Thanks!
If you check help latex, it will tell you that default size is 5 x 3 inches.
Since you set size square, there will be for sure an "unwanted" left and right margin.
What you can do to at least minimize the margins is to set the terminal size to square size as well, e.g. to 3 x 3 inches.
However, keep in mind the graph size is square but x and y axes have tics and labels which require space depending on numbers and labels which might be different for x and y.
set term epslatex standalone size 3 in, 3 in
From help latex:
Syntax:
set terminal {latex | emtex} {default | {courier|roman} {<fontsize>}}
{size <XX>{unit}, <YY>{unit}} {rotate | norotate}
By default the plot will inherit font settings from the embedding
document. You have the option of forcing either Courier (cmtt) or
Roman (cmr) fonts instead. In this case you may also specify a
fontsize. Unless your driver is capable of building fonts at any size
(e.g. dvips), stick to the standard 10, 11 and 12 point sizes.
...
Maybe, there are LaTeX commands to crop the graph to its bounding box.
Thanks to #AlainMarigot help, I change the system to Lua tikz with the option tightboundingbox.
Looks good, but not exactly same as epslatex.

Latex figure caption overlaps gnuplot figure generated with the epslatex terminal

I have to plot 4 graphs without vertical spaces between them and add a caption in my tex document. The problem is that the caption is overlapped with the x-axis label because of the zero bottom margin, I think.
The gnuplot file is something like this
set term epslatex
set output 'foo.tex'
set xrange [-1:1]
set yrange [-1:1]
set multiplot layout 4,1
set ylabel '$y$'
unset xlabel
unset xtics
set tmargin 0
set bmargin 0
plot x w lines
plot x*x w lines
plot x*x*x w lines
set xlabel '$x$'
set xtics
plot x*x*x*x w lines
unset multiplot
and the tex file is
\documentclass[a4paper,11pt]{toptesi}
\usepackage{graphicx}
\begin{document}
\begin{figure}
\input{foo}
\caption{bla bla}
\end{figure}
\end{document}
and the "bla bla" comes over the x label... I tried to put an set bmargin "something" before the last graph but this have the problem that the last graph hasn't the size of the first three anymore... How to fix the size of plots but allow a bmargin for the tex caption?
Try this code...
set term epslatex size <width> <height>
set output 'foo.tex'
set xrange [-1:1]
set yrange [-1:1]
set multiplot
# setup sizes of single plots
set size 1,.25
set ylabel '$y$'
unset xlabel
unset xtics
set tmargin 0
set bmargin 0
# set bottom left corner of current plot
set origin 0,.75
plot x w lines
set origin 0,.5
plot x*x w lines
set origin 0,.25
plot x*x*x w lines
set xlabel '$x$'
set xtics
# set bmargin back
set bmargin 3 #might be enought for place xlabel, try it...
set origin 0,0
plot x*x*x*x w lines
unset multiplot
set out
set term pop
But... The bottom panel is smaller than others, so you must increase vertical size of bottom panel (using set size 1, a) a>0.25 and decrease vertical size of others (set size 1, b before each plot command) and satisfy that a+3b=1. This fine tuning will depend on size parameter of epslatex terminal.
Much much better solution might be this:
...
set size 0,.25
set tmargin 0
set bmargin 1
set origin .75,0
plot ...
set tmargin -1
set bmargin 2
set origin .5,0
plot ...
set tmargin -2
set bmargin 3
set origin .25,0
plot ...
set tmargin -3
set bmargin 4
set origin .25,0
plot ...
Now we might have enough space for bottom xlabel and all of the panels have same height. Unfotunatelly gnuplot 4.6.3 interprets tmargin -3 as tmargin 0. So we can't use it right now... May be in some newer version.

How to remove unknown slits when using filledcurve in Gnuplot (epslatex)?

I'm now trying to use filledcurve in gnuplot 4.6, patchlevel 1. Following shows the sample script:
set term epslatex
set output "figure.tex"
set xlabel "\\huge{x-axis}"
set ylabel "\\huge{y-axis}"
set format xy "\\LARGE{%.0f}"
set xrange [0.0:10.0]
set yrange [0.0:100.0]
set xtics 2.0
set ytics 20.0
set xtics offset 0, -0.3
f1(x) = x**1
f2(x) = x**2
f3(x) = x**3
set nokey
plot '+' using 1:(f2($1)):(f3($1)) with filledcurve lt 1 lc rgb "gray60",\
'+' using 1:(f1($1)):(f2($1)) with filledcurve lt 1 lc rgb "gray40",\
'+' using 1:(0.0):(f1($1)) with filledcurve lt 1 lc rgb "gray20"
I don't known why, but it seems that there are white annoying slits between bars. It cannot be get rid of even if I increase the number of set samples.
Is there any idea to remove these slits?
Unfortunately, this is a viewer problem related to the drawing of adjacent filled polygons, see also problematic Moire pattern in image produced with gnuplot pm3d and pdf output or the bug report #1259 cairolatex pdf fill patterns.
In your case you can use a workaround:
When you have only two columns in the using statement, the area is drawn as closed polygon and doesn't show these artifacts (filledcurves closed). So you must fill the area between each curve and the x1 axis (with filledcurves x1).
Because of a bug in the clipping of curves which exceed the y-range, you must do the clipping of the f3 curve yourself (i.e. use f3($1) > 100 ? 100 : f3($1)). This bug is fixed in the development version.
So you script is:
set term epslatex standalone
set output "figure.tex"
set xlabel "\\huge x-axis"
set ylabel "\\huge y-axis"
set format xy "\\LARGE %.0f"
set xrange [0.0:10.0]
set yrange [0.0:100.0]
set xtics 2.0
set ytics 20.0
set xtics offset 0, -0.3
f1(x) = x**1
f2(x) = x**2
f3(x) = x**3
set nokey
plot '+' using 1:(f3($1) > 100 ? 100 : f3($1)) with filledcurve x1 lt 1 lc rgb "gray60",\
'+' using 1:(f2($1)) with filledcurve x1 lt 1 lc rgb "gray40",\
'+' using 1:(f1($1)) with filledcurve x1 lt 1 lc rgb "gray20"
set output
system('latex figure.tex && dvips figure.dvi && ps2pdf figure.ps')
with the result (using 4.6.1):
Note also, that LaTeX commands like \huge don't take arguments, but are switches. Test e.g. \huge{A}BC, this will make all letter huge. Usually you must limit the scope of \huge with brackets like {\huge ABC}, but if the whole label is affected, it is enough to use set xlabel "\\huge x-axis". That doesn't change anything in your case, but may give you troubles in other circumstances :)

Resources