# How can I use trigonometric functions and tick labels with pgfplots?

\begin{tikzpicture}
\begin{axis}[
axis lines=middle,
samples=100,
ymax=5,legend pos=north east,
legend style={draw=none}
]
\addlegendentry{$e^{x}$};
\node[pin={90:$f(x)=\lvert\log x\rvert$},inner sep=0pt]
at (axis cs:{2,log10(2)}) {};
\node[pin={0:$f(x)=e^{x}$},inner sep=0pt]
at (axis cs:{1,exp(1)}) {};
\node[anchor=north west]
at (axis description cs:0,0.5)
{$\lvert e^{x}\rvert$};
\end{axis}
\end{tikzpicture}


I have used these code to generate the curves. It shown to me like:

But after making change in the function abs(log(x)) into sin(x), like in the following codes,

 \begin{tikzpicture}
\begin{axis}[
axis lines=middle,
samples=100,
ymax=5,legend pos=north east,
legend style={draw=none}
]
\addlegendentry{$e^{x}$};
\node[pin={90:$f(x)=\lvert\log x\rvert$},inner sep=0pt]
at (axis cs:{2,log10(2)}) {};
\node[pin={0:$f(x)=e^{x}$},inner sep=0pt]
at (axis cs:{1,exp(1)}) {};
\node[anchor=north west]
at (axis description cs:0,0.5)
{$\lvert e^{x}\rvert$};
\end{axis}
\end{tikzpicture}


I got the image as

Requirements

(1) I should have my sin x graph with this graphs.

(2) My x-axis tick must have $-\pi, \frac \pi 2 ,...$ means I want radian measure ticks.

How do I do this.?

Besides fixing it by writing as sin(x), you can switch from degrees to radian with pgfplots 1.11 and newer:

\pgfplotsset{trig format plots=rad}


After adding it to your drawing, I got the sine function nicely displayed:

This was first mentioned on TeXwelt by the pgfplots author in an answer to "Kann man bei pgfplots die Argumente trigonometrischer Funktionen von Grad auf Radiant umstellen".

Furthermore, you could get radian in ticks by

  xtick = {-1.5707, 0, ..., 6.28318},
xticklabels = {$-\frac{\pi}{2}$, 0,
$\frac{\pi}{2}$, $\pi$, $\frac{3\pi}{2}$, $2\pi$}