Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

share|improve this question
2  
Adding, ytick={0,0.25,...,2},yticklabel={\pgfmathparse{deg(pi*\tick)}\pgfmathprintnumbe‌​r[fixed,precision=0]{\pgfmathresult}} does something but I'm not sure if that's what you want. –  percusse Jul 31 '13 at 11:39
    
I don't know where to add that - I tried it but ´! Undefined control sequence. \pgfplots@yticklabel ...tick )}\pgfmathprintnumber[fixed,precision=0]´ was the result. –  oerpli Jul 31 '13 at 11:44
    
Added a picture of what I'm trying to achieve. –  oerpli Jul 31 '13 at 11:46
    
@oerpli: Do you have a particular reason for using gnuplot? (Because PGF uses degrees by default, so that wide sidestep the problem) –  Jake Jul 31 '13 at 11:49
    
@oerpli You add it to the end of axis options after bottom word –  percusse Jul 31 '13 at 11:51

1 Answer 1

up vote 4 down vote accepted

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}
share|improve this answer
    
haha, thanks. that was way easier than i expected. missed the forest for the trees. –  oerpli Jul 31 '13 at 12:08

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.