[Tex/LaTex] Axis labels and ticks in degree, plot in radian

pgfplotsplottikz-pgf

I've got a plot – the x axis is in radian (from pi/2 to pi) and with gnuplot it works like a charm – the problem is – that my x-axis labeling should be in degree (-90, -75,…,90) and i'm kinda stuck.

Should i change everything to degree or is there an option to achieve this with altering the ticks?

 \documentclass{article}
 \usepackage{tikz,pgfplots}
 \begin{document}
 \begin{tikzpicture}[plot/.style={very thick,raw gnuplot,mark=none,black}]
 \begin{axis}[minor y tick num=3, minor x tick num=1, width=\textwidth, domain=-pi/2:pi/2,
 ymin=0, ymax=1.3, xmin=-1.571, xmax=1.571, grid=both, y=5cm, axis y line=left, axis x line=bottom]
 \addplot gnuplot [plot,red]
     { ag1(x) = 0.5 + 0.2*sin(10*x);plot[-pi/2:pi/2]ag1(x)};
 \end{axis} \end{tikzpicture}
 \end{document}

It should look similar to this picture:
enter image description here

Best Answer

You can set gnuplot to use degrees for angles with set angles degrees;:

 \documentclass{article}
 \usepackage{tikz,pgfplots}
 \begin{document}

 \begin{tikzpicture}[plot/.style={very thick,raw gnuplot,mark=none,black}]
 \begin{axis}[
    minor y tick num=3,
    minor x tick num=1, 
    width=\textwidth,
    ymin=0, ymax=1.3,
    grid=both, y=5cm,
    axis y line=left,
    axis x line=bottom
 ]
 \addplot gnuplot [plot,red] {
   set angles degrees;
   ag1(x) = 0.5 + 0.2*sin(10*x);
   plot [-90:90] ag1(x)
 };
 \end{axis} \end{tikzpicture}
 \end{document}

Alternatively, you can convert your result to degrees using an x filter:

 \documentclass{article}
 \usepackage{tikz,pgfplots}
 \begin{document}

 \begin{tikzpicture}[plot/.style={very thick,raw gnuplot,mark=none,black}]
 \begin{axis}[
    minor y tick num=3,
    minor x tick num=1, 
    width=\textwidth,
    ymin=0, ymax=1.3,
    grid=both, y=5cm,
    axis y line=left,
    axis x line=bottom,
    x filter/.code=\pgfmathparse{#1*360/(2*pi)}
 ]
 \addplot gnuplot [plot,red] {
   ag1(x) = 0.5 + 0.2*sin(10*x);
   plot [-pi/2:pi/2] ag1(x)
 };
 \end{axis} \end{tikzpicture}
 \end{document}
Related Question