5
\begin{tikzpicture}
\begin{axis}[
  axis lines=middle,
  samples=100,
  ymax=5,legend pos=north east,
  legend style={draw=none}
]
\addplot[forget plot,cyan,domain=0.001:8] {abs(log10(x))};
\addplot[forget plot,red!70!black,domain=-2:4] {2+exp(abs(x))};
\addplot[green,thick,domain=-2:3] {exp(x)};
\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:

output

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}
]
\addplot[forget plot,cyan,domain=0.001:8] {sin(x)};
\addplot[forget plot,red!70!black,domain=-2:4] {2+exp(abs(x))};
\addplot[green,thick,domain=-2:3] {exp(x)};
\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

enter image description here

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.?

David
  • 1,964

1 Answers1

8

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:

sine function output

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$}
Stefan Kottwitz
  • 231,401