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
Related
I'm using gnuplot in conjunction with cairolatex to produce my graphs and save them as .tex files, which I can easily embed in a LateX report using \input. However, I'm running into some problems when it comes to setting the key. Since key overlaps the data points, I used set key at x, y in order to give it a little offset, as such:
In the picture to the left, I tried to shift the key up, but it leaves the screen for some reason, as if there was a limit to the avaible room the graph can take up. On the right you can see what happens if a don't do anything. So the solution may be in the gnuplot or on the LateX side, whichever works.
There are a ton of options to "set key". The simplest answer to your question is "set key outside", but you may still want to adjust the positioning more explicitly. In this case gnuplot will make the graph smaller so that there is room beside it for the key.
set term cairolatex pdf standalone
set output 'key.tex'
set multiplot layout 2,1
set key
plot for [i=2:8] sin(x/i) title sprintf("$sin(x/%d)$", i)
set key outside
replot
unset multiplot
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)
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.
I have gnuplot file that is outputting quite nicely in EPS but I'm suffering some issues when it comes to the labels. For some reason, a random figure (') is being inserted before the each label. This isn't being produced in a PNG export.
Example gnuplot error picture
The gnuplot file is below
set term postscript eps enhanced
set datafile separator ","
set datafile missing "NULL"
set decimal locale
set output 'Average_Costs_Plotted.eps'
set grid
set key left
set ytics nomirror
set xtics nomirror
set format y "£%'.0f"
set ylabel "Total Loss Estimate \n Based on Average Cost Per m^2"
set xlabel "Area Damaged m^2"
plot "Average_Costs_Upto_10000mSQM.csv" using 1:2 axis x1y1 title 'Industrial Processing' w l lw 2
Well that'll teach me to RTFM.
Postscript doesn't support unicode as mentioned above - however there are octal codes for symbols to insert them.
The £ is input by using the code \243