epslatex in gnuplot does not give right output - latex

I am using the following script to generate a simple eps image:
set terminal epslatex 8
set output 'sample1.tex'
set size 0.75,0.75
set xrange [-pi:pi]
set yrange [0:1.2]
set xlabel "$x$"
set ylabel "$y$"
plot sin(x)*sin(x) title "$\\sin^2(x)$"
However, when I run it in gnuplot
gnuplot> load "sample.gpi"
I got a blank image, just the grids without numbers are shown.
Any suggestion what I'm doing wrong?

You are probably viewing the sample1-inc.eps file. But you must compile the output LaTeX-file first. For this it is very convenient to use the standalone option and compile from within the script itself:
set terminal epslatex 8 standalone
set output 'sample1.tex'
set size 0.75,0.75
set xrange [-pi:pi]
set yrange [0:1.2]
set xlabel "$x$"
set ylabel "$y$"
plot sin(x)*sin(x) title "$\\sin^2(x)$"
set output # finish the current output file
system('latex sample1.tex && dvips sample1.dvi && ps2pdf sample1.ps')
Now you can load 'sample1.gpi' and view the complete output as sample1.ps or sample1.pdf. If you are on Windows you may need to compile with three separate system calls (just guessing):
system('latex sample1.tex')
system('dvips sample1.dvi')
system('ps2pdf sample1.ps')

Related

gnuplot epslatex unable to get replot

When I use replot in the epslatex terminal, anything I replot is not showing up in the final output.
reset session
set terminal epslatex size 5.0in,4in color colortext font ',10' standalone
set output 'plots.tex'
set size square
plot sin(x)
replot cos(x)
set output
When I use , and plot in the same line, I get correct outputs.
reset session
set terminal epslatex size 5.0in,4in color colortext font ',10' standalone
set output 'plots.tex'
set size square
plot sin(x), cos(x)
set output
replot is very convenient becuase I can use set and change settings.
My question is how to use replot in gnuplot that prints in LaTeX.
In gnuplot both commands are different. Using plot sin(x) followed by replot cos(x) draws two plots: one with sin(x) and another one with the result of the previous plot command (ie sin(x)) and cos(x). Indeed
plot sin(x)
replot cos(x)
is absolutely equivalent to
plot sin(x)
plot sin(x), cos(x)
If you display the 'plots-inc.eps' or if you change the terminal to pdf, you have two pages, the first with the plot of sin(x) and the second with both.
The plots.tex file is supposed to be included in a some tex source and only contains one plot. The actual function that is plotted in the .tex file is the last one (with sin(x) and cos(x)). This code is adapted to dvi output and if you format it with latex plots.tex (and not pdflatex plots.tex) and view the .dvi file with xdvi (or whatever), you can verify that a plot with both functions is present. For unknown reasons, with pdflatex, only the sin(x) appears (but both are in the .tex code and there is the legend for cos(x)).
Here is what I get in the .dvi file:
We can do a zoom on this dvi file.
And compare it to the second plot if we use a pdf terminal.
As you can see, the plot rendering is worse with the dvi file and the function is smoother with the pdf output.
I think the problem is that the epslatex terminal is a very old driver. It was the default in the nineties, but with modern TeX engines, almost no one uses it anymore and I am not sure that it is actively maintained.
This probably explains the problems : the incomplete plot with pdflatex and the lower quality of the rendering. Most probably this driver has never really been adapted to engines like pdflatex or lualatex.
Unless you absolutely need dvi, I would suggest you to switch to another driver. Generate your plots as pdf and use \includegraphics to load them. The plot quality will be increased, but you will also gain all the flexibility of \includegraphics to resize, rotate, clip or do whatever you want to your plots.
Please note that the pdf driver will generate one plot per page and with your initial code there are two plots. You can include a specific page (ie plot) of the pdf with the 'page=' option of \includegraphics, but the simpler is to select different output files per plot.
set output 'plots.pdf'
plot sin(x)
set output 'plots2.pdf'
replot cos(x)

Combine gnuplot with latex: method and output

I'm running the following script:
#!/bin/bash
gnuplot -e "set t latex ; set size 0.5,1; set output 'grafico.tex';
set xtics ('$\frac{-\pi}{2}$' -pi/2, 0, '$\frac{\pi}{2}$' pi/2); set xrange [-pi/2:pi/2];
set yrange [-2:2]; set ylabel '$ f(x)$'; set xlabel '$\theta$';
plot sin(x); pause -1 'hit return to continue'"
pdflatex latex
atril latex.pdf
Output 1
As a beginner both with programming and gnuplot, I want to be sure that's the correct way to do it. My doubt come from the output, it doesn't looks very good (the resolution, mainly). Is there any simple improvement i'm missing? Any change to improve the plotting technique and enhance the result will be welcome.
Output 2
Changing latex to cairolatex pdf as suggests #Ethan Merritt returns:
which is much better.
gnuplot's original latex terminal, the one you get by saying "set term latex", is horrible by modern standards. Use one of the more recent ones. My favorite is the tikz terminal:
gnuplot>
set term tikz standalone size 5cm, 7cm
set output 'grafico.tex'
set xtics ('$\frac{-\pi}{2}$' -pi/2, 0, '$\frac{\pi}{2}$' pi/2)
set xrange [-pi/2:pi/2]; set yrange [-2:2];
set ylabel '$ f(x)$'; set xlabel '$\theta$';
plot sin(x)
unset output
system("pdflatex grafico")
Notes:
You should probably set the size as part of the set term command. If you use set size your output will contain large blank areas
Your local copy of gnuplot might not support the tikz terminal. In that case you could use set term cairolatex pdf instead, with everything else the same.
gnuplot has other (too many!) latex-based terminals also, but I suggest starting with tikz or cairolatex.

Gnuplot no lines drawn

My problem is that gnuplot does not draw any lines. That applies to linespoints and lines. Here is my script:
set terminal postscript
set output "bla.eps"
set datafile separator "\t"
set autoscale
set grid
set yrange [0:12]
unset log
unset label
set xtic auto
set xtics font "Times-Roman, 10"
set ytic auto
plot "times.dat" using 1:($4/1000):xtic(1) title "naive" with linespoints lc rgb "red" pt 7 ps 1.3
My .dat file has as the first column some data that I want to intepret as a text, while other columns are numbers. I just don't see any lines printed on the screen. Points are just fine. Even if I make the first column a number column, or I use lines, it doesn't matter, there is no line. Any clue?
A typical reason for having points drawn, but no connecting lines is the presence of blank lines in the data file:
Consider the data file
1
2
3
Plotted with
plot 'data.dat' using 0:1 with linespoints
it draws only the points, but no connecting lines.
This behavior is intended as it allows you to structure your data file, get these continuities where you want them, and allows you to access different parts of a data file using every or index (when having two blank lines).
This does appear to be broken. I get I have blank lines in the file
but it is unexpected behaviour.
plot "data.txt" using 1:2 with linespoints
Used to draw lines between the points but now it just draws the points;
because of the blank lines.....
$ gnuplot --version
gnuplot 5.0 patchlevel 3

How to Batch Scaling images and Padding in White color with Automator in Mac OS

Using Automator in Mac OS i am trying to do batch Padding and scaling images.
I tried to Batch Scale images to a particular size along with padding.
It doesn't work if i drag and drop entire folder into the Automator, Only works for multiple image drag and drop.
And for padding i am getting the Color Black where i need it to be white
I Already tried using the Created Automator Application>Library>Photos>Pad Images
And then gave Canvas dimensions then Scale images before padding option
The Automate Pad Image action fills the canvas with black as the default color. Sadly, there is no way to modify this default action.
What you can do, is add a "Run AppleScript" action to call the sips command line tool to pad the image using the color that you want.
To do this, click on the Utilities Action in the Automator sidebar and add a "Run AppleScript" Actions.
Replace the default AppleScript code with the following code:
on run {input, parameters}
repeat with this_file in input
set this_path to the quoted form of the POSIX path of this_file
do shell script "sips " & this_path & " -p 50 50 --padColor FFFFFF -i"
end repeat
return input
end run
The -p argument specifies the width and height of the padding. The --padColor argument specifies the color. In this case, the color is white. FFFFFF is equal to 255, 255, 255 in RGB colors.
You can type "sip --help" on the command line in the terminal to see all of the cool things that the command can do.
I had the same question - found the answer today without spending money.
SIPS is built-in to Mac OS X - command line graphics scripting.
I have attached a screenshot of my automator script:
- make a copy of your images folder first
- select your image folder for resizing
- in the command line setting I have hard coded 300 as my images needed to be padded to 300px
![Use automator with Unix Commandline][1]
Image not allowed

Gnuplot multiplot positions all text incorrectly in epslatex terminal

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

Resources