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)
Related
I want to produce a plot with matplotlib and use the command
plt.rc('text', usetex=True)
to render the text with LaTeX. I output the file with plt.savefig as a pdf. When I include the above command, I get a nice TeX font but the file size increases by a factor 20 or more, depending on the amount of text in the plot (compared to the output of the same script with plt.rc('text', usetex=True) commented out).
Is there any way to have TeX rendering without increasing the file size?
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.
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
I switched from tikz to gnuplot for drawing math diagrams recently. I find them very different.
I want to draw a circle, so I created a .gpi file:
set terminal latex
set out 'gp.tex'
set xrange [-5:5]
set yrange [-5:5]
set object 1 circle at 0,0 size char 1 fillcolor rgb "black" fillstyle solid
plot NaN
set out
set terminal x11
plot NaN
And I loaded it in gnuplot.
The circle in x11 terminal is filled, as expected:
http://i.imgur.com/xDmlTa4.png
But the one compiled from gp.tex is a hollow circle:
http://i.imgur.com/7LNzvmW.png
Why? How can I produce a filled circle in the tex file as well?
The latex terminal is very old and doesn't support filled circles. You should use one of the other LaTeX-related terminals like epslatex, cairolatex or tikz which support filled circles.
See the output of the test command to see which features are supported by a terminal. For filled circles, filled polygons must be supported. For latex you get:
I have the following gnuplot plot embedded in my Latex document:
\begin{gnuplot}[terminal=epslatex,terminaloptions={color size 14.5cm, 9cm}]
set view map
unset surface
unset key
unset xtics
unset ytics
unset ztics
set contour base
set cntrparam levels discrete 2,4,8,16,32,64,128,256,512
set isosamples 100
splot y**2 + 0.1*x**2 notitle
\end{gnuplot}
The plot is alright. All I want to achive is that the contour lines all have the same style, i.e. line type and the same colour, black if possible.
Thanks for any advices.
I don't know about the latex terminal, but you could try:
splot y**2 + 0.1*x**2 notitle lc rgb "#000000"
http://www.gnuplot.info/demo/contours.html (see the section where they draw all the contours in the same color -- It's the last example on that page)
EDIT
It looks like the coloring of the contours is controlled by {un}set clabel. So if you just add unset clabel to your script, then the contours should probably show up black (with the lc rgb "#000000" that I had above. Note that unset clabel implies unset key. To achieve this with the ability to add a key is a little more tricky...
in case you ever need to keep the labels...
You'll likely need to set term push to save the current terminal. set term unknown to make the output go nowhere. set table "junk.dat" and then issue your plot commmand as normal. This will write the contours to a file "junk.dat" which can then be splotted with lines after a set term pop to restore the old terminal settings (you'll probably need some variant of title columnhead and maybe an index/every as well to get the labels to appear correctly...) -- I'm not actually sure if the set term push/pop commands are necessary in this case. Anyway, plotting things to tables with gnuplot is something that I've done a number of times for a number of different applications. It's a great tool to keep in mind.