I do not know if what I am bringing up is a feature or a bug.
I am trying to get a cos x
trig plot in degrees generated by gnuplot
and plotted by TikZ
. My .gnuplot
file looks like this:
set table "trig.cosinex.table"; set format "%.5f"
set angles degrees; set samples 500; plot [x=0:360] cos(x)
When I compile my .tex
file with Tikz/lualatex, the .gnuplot
file becomes
set table "trig.cosinex.table"; set format "%.5f"
set samples 500; plot [x=0:360] cos(x)
The set angles degrees;
part is deleted.
The gnuplot-relevant line in my .tex
file is:
\draw [domain=0:360, samples=500, smooth] plot[id=cosinex] function {cos(x)}; % anm I missing a prefix here?
Kindly note that:
a. I hand generate the .table
file from the .gnuplot
file by running it through gnuplot.
b. TikZ/lualatex does not generate a .table
file even if it does not exist (contrary to manual?) but only overwrites the .gnuplot
file.
My questions are:
- How can I get
TikZ
to specify the angles to be degrees in the.gnuplot
file that it overwrites? [If overwriting cannot be prevented.] - How to prevent
TikZ
from overwriting my.gnuplot
file in the first place? [After hand-compilation withgnuplot
, the.table
is left untouched byTikZ
during multiple compilations as specified but the.gnuplot
file is altered as above. So, repeat hand-compilation produces a wrong.table
file and does not give correct results.]
Thanks.
Best Answer
When you use
\draw ... plot ... function {<plot command>}
, the first thing TikZ does is generate the.gnuplot
file with the default options and the<plot command>
. Then it tries to executegnuplot
with the.gnuplot
file. This is a feature (it's whatfunction
is supposed to do), and works as described in the manual.If all you want to do is plot the
.plot
file generated by callinggnuplot
manually, then you shouldn't use thefunction
command, but simplyfile
. In your case, you could useNote that the
domain
,samples
andid
keys have no effect when plotting data from a file.If you want to use the
function
command (i.e. you want to generate the.gnuplot
file from within TikZ) with degrees, you can useraw gnuplot
to provide the appropriate options:Or you could change the
.gnuplot
skeleton usingin your preamble. Then you can plot your function as desired: