# Wrong plot in pfgplots

I want to plot a function in a LaTeX document. Usually I use either Mathematica, Matlab or Root. At this point I want to use pgfplots in order to keep my document in a complete LaTeX layout. The thing is that pgfplots doesn't produce the exact plot as Mathematica, let alone the weird thing that's going on with the y-axis.

My code is

\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xlabel=$x$,
ylabel={$d\sigma$}
]
\end{axis}
\end{tikzpicture}
\end{document}


My output is

while Mathematica gives

Any ideas on that?

• Use \addplot[blue,domain=0:3]{1-sin(deg(x/2))^2};. It needs degrees. – percusse Jun 29 '13 at 8:07
• @percusse: Thank you very much for your answer! You are absolutely right! Thank's alot! Would you mind answering the question, so as to accept you answer? – Thanos Jun 29 '13 at 8:14

There are two problems with your code. First, the domain 1:2*pi means the interval [1, 2pi]. In Mathematica, you asked for the interval [0,pi]. So replacing 1:2*pi by 0:pi should give you the correct interval to draw.

The second problem is that the sin function expects an argument in degrees, not radians. To convert from radians to degrees, you can use the deg function. Replacing sin(x/2) by sin(deg(x)/2) will do the trick.

Manually overriding the minimum/maximum x and y values, and removing the frame can be done by setting the appropriate options. The following code produces more or less the same plot as your Mathematica plot:

\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.8}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xmin=0, xmax=3.4,
ymin=0, ymax=1.1,
axis lines=left,
xlabel=$x$,
ylabel={$d\sigma$}
]

• Is there a way to plot the x-axis in degrees and a legend? – Thanos Jun 29 '13 at 8:19
• Yeah sure. Change the domain to 0:180 and remove the deg again. – yyzz Jun 29 '13 at 8:19
• To convert from radians to degrees, you may use x/2 r instead of deg(x)/2. – Paul Gaborit Jun 29 '13 at 8:23