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.
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
I am trying to visualize a time series data set on one plot as a pseudo 3d figure. However, I am having some trouble getting the filledcurves capability working properly. It seems to be adding an unwanted border at the "bottom" of my functions and I do not know how to fix this.
This is my current set up: I have nb_of_frames different files that I want to plot on one figure. Without the filledcurves option, I can do something like this
plot for [i=1:nb_of_frames] filename(i) u ($1):(50.0 * $2 + (11.0 - (i-1)*time_step)) w l linewidth 1.2 lt rgb "black" notitle
which produces a figure like this:
no fill options
Instead of doing this, I want to use the filledcurves option to bring my plots "forward" and highlight the function that is more "forward" which I try to do with:
plot for [i=1:nb_of_frames] filename(i) u ($1):(50. * $2 + (11. - (i-1)*time_step)) w filledcurves fc "white" fs solid 1.0 border lc "black" notitle
This produces a figure as follows:
This is very close to what I want, but it seems that the border option adds a line underneath the function which I do not want. I have tried several variants of with filledcurves y1=0.0 with different values of y1, but nothing seems to work.
Any help would be appreciated. Thank you for your time.
Here is another workaround for gnuplot 5.2.
Apparently, gnuplot closes the filled area from the last point back to the first point. Hence, if you specifiy border, then this line will also have a border which is undesired here (at least until gnuplot 5.4rc2 as #Ethan says).
A straightforward solution would be to plot the data with filledcurves without border and then again with lines. However, since this is a series of shifted data, this has to be plotted alternately. Unfortunately, gnuplot cannot switch plotting styles within a for loop (at least I don't know how). As a workaround for this, you have to build your plot command in a previous loop and use it with a macro # (check help macros) in the plot command. I hope you can adapt the example below to your needs.
Code:
### filledcurves without bottom border
reset session
set colorsequence classic
$Data <<EOD
1 0
2 1
3 2
4 1
5 4
6 5
7 2
8 1
9 0
EOD
myData(i) = sprintf('$Data u ($1-0.1*%d):($2+%d/5.)',i,i)
myFill = ' w filledcurves fc "0xffdddd" fs solid 1 notitle'
myLine = ' w l lc rgb "black" notitle'
myPlotCmd = ''
do for [i=11:1:-1] {
myPlotCmd = myPlotCmd.myData(i).myFill.", ".myData(i).myLine.", "
}
plot #myPlotCmd
### end of code
Result:
I can reproduce this in gnuplot 5.2.8 but not in the output from the release candidate for version 5.4. So I think that some bug-fix or change was applied during the past year or so. I realize that doesn't help while you are using verion 5.2, but if you can download and build from source for the 5.4 release candidate that would take care of it.
Update
I thought of a work-around, although it may be too complicated to be worth it.
You can treat this as a 2D projection of a 3D fence plot constructed using plot style with zerrorfill. In this projection the y coordinate is the visual depth. X is X. Three quantities are needed on z: the bounding line, the bottom, and the top. I.e. 5 fields in the using clause: x depth zline zbase ztop.
unset key
set view 90, 180
set xyplane at 0
unset ytics
set title "3D projection into the xz plane\nplot with zerrorfill" offset 0,-2
set xlabel "X axis" offset 0,-1
set zlabel "Z"
splot for [i=1:25] 'foo.dat' using ($1+i):(i/100.):($2-i):(-i):($2-i) \
with zerrorfill fc "light-cyan" lc "black" lw 2
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: