7

I want to contour plot the curves (y^2)/2-cos(x)=c with the following code, but there are only straight line in the output figure. What's wrong? Any help or suggestions will be appreciated!

\begin{tikzpicture}
\begin{axis}[domain=-10:10,view={0}{90}] 
\addplot3[contour gnuplot={number=15,labels=false},thick]  {(y^2)/2-cos(x)};
\end{axis}
\end{tikzpicture}
2
  • 1
    is it (y^2)/2 - cos(x) or y^(2/(2-cos(x))) or is it [1/(2-cos(x))]y^2 Oct 26, 2013 at 2:24
  • PGFPlots uses degrees, so your domain is too small.
    – Jake
    Oct 26, 2013 at 7:12

1 Answer 1

7

PGFPlots uses degrees for trigonometric functions, not radians. You can convert your values to degrees using deg(x) instead of just x:

\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
\begin{axis}[domain=-10:10,view={0}{90}, samples=60, samples y=60] 
\addplot3[contour gnuplot={number=15,labels=false},thick]  {(y^2)/2-cos(deg(x))};
\end{axis}
\end{tikzpicture}
\end{document}
3
  • what is the reason that I get with xelatex a completely other output? I have current TL 2013. My output: perce.de/pub/xelatex.png
    – user2478
    Oct 26, 2013 at 12:02
  • @Herbert thanks for the helpful question. That is a bug; the input file for gnuplot receives ^^I as column separator; but that does not seem to work in xelatex (which generates three separate chars). I will take care of it. Oct 27, 2013 at 18:21
  • 2
    @Herbert I have fixed it in the developer version. Oct 27, 2013 at 18:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .