# Function graphs

Can you help me with my page of function graphs? I could make the first four graphs but there is a problem with plotting by others. All graphs should have the same size like the first four ones. Thank you!

\documentclass{article}
\usepackage{pgfplots}
\usepackage{subfigure}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric,calc,arrows,decorations.markings,decorations.pathmorphing}
\newcommand{\tg}{\mathop{\mathrm{tg}}}
\newcommand{\cotg}{\mathop{\mathrm{cotg}}}
\newcommand{\arctg}{\mathop{\mathrm{arctg}}}
\newcommand{\arccotg}{\mathop{\mathrm{arccotg}}}
\begin{document}
\begin{figure}[H]
\centering
\subfigure
{
\begin{tikzpicture}[smooth,scale=0.8]
\draw[thick,->] (-2,0) -- (2,0) node[below] {$x$};
\draw[thick,->] (0,-1.5) -- (0,1.5) node[right] {$y$};
\draw[blue,thick,domain=-1.5:1.5] plot (\x,{1}) node[above] {$y=c$};
\end{tikzpicture}
}
%
{
\begin{tikzpicture}[smooth,scale=0.8]
\draw[thick,->] (-2,0) -- (2,0) node[below] {$x$};
\draw[thick,->] (0,-1.5) -- (0,1.5) node[right] {$y$};
\draw[blue,thick,domain=-1.5:1.5] plot (\x,{\x}) node[above] {$y=x$};
\end{tikzpicture}
}
%
\subfigure
{
\begin{tikzpicture}[smooth,scale=0.8]
\draw[thick,->] (-2,0) -- (2,0) node[below] {$x$};
\draw[thick,->] (0,-1.5) -- (0,1.5) node[right] {$y$};
\draw[blue,thick,domain=-1.5:1.5] plot (\x,{\x*\x}) node[above] {$y=x^2$};
\end{tikzpicture}
}
%
\subfigure
{
\begin{tikzpicture}[smooth,scale=0.8]
\draw[thick,->] (-2,0) -- (2,0) node[below] {$x$};
\draw[thick,->] (0,-1.5) -- (0,1.5) node[right] {$y$};
\draw[blue,thick,domain=-1.15:1.15] plot (\x,{\x*\x*\x}) node[above]     {$y=x^3$};
\end{tikzpicture}
}
%
\subfigure
{
\begin{tikzpicture}[smooth,scale=0.8]
\draw[thick,->] (-2,0) -- (2,0) node[below] {$x$};
\draw[thick,->] (0,-1.5) -- (0,1.5) node[right] {$y$};
\draw[blue,thick,domain=-1.5:1.5] plot (\x,{\x}) node[above] {$y=\frac{1}{x}$};
\end{tikzpicture}
}
%
\subfigure
{
\begin{tikzpicture}[smooth,scale=0.8]
\draw[thick,->] (-2,0) -- (2,0) node[below] {$x$};
\draw[thick,->] (0,-1.5) -- (0,1.5) node[right] {$y$};
\draw[blue,thick,domain=-1.5:1.5] plot (\x,{\x}) node[above]     {$y=\sqrt{x}$};
\end{tikzpicture}
}
%
\subfigure
{
\begin{tikzpicture}[smooth,scale=0.8]
\draw[thick,->] (-2,0) -- (2,0) node[below] {$x$};
\draw[thick,->] (0,-1.5) -- (0,1.5) node[right] {$y$};
\draw[blue,thick,domain=-1.5:1.5] plot (\x,{\x}) node[above] {$y=e^x$};
\end{tikzpicture}
}
%
\subfigure
{
\begin{tikzpicture}[smooth,scale=0.8]
\draw[thick,->] (-2,0) -- (2,0) node[below] {$x$};
\draw[thick,->] (0,-1.5) -- (0,1.5) node[right] {$y$};
\draw[blue,thick,domain=-1.5:1.5] plot (\x,{\x}) node[above] {$y=\ln{x}$};
\end{tikzpicture}
}
%
\subfigure
{
\begin{tikzpicture}[smooth,scale=0.8]
\draw[thick,->] (-2,0) -- (2,0) node[below] {$x$};
\draw[thick,->] (0,-1.5) -- (0,1.5) node[right] {$y$};
\draw[blue,thick,domain=-1.5:1.5] plot (\x,{\x}) node[above] {$y=\sin(x)$};
\end{tikzpicture}
}
%
\subfigure
{
\begin{tikzpicture}[smooth,scale=0.8]
\draw[thick,->] (-2,0) -- (2,0) node[below] {$x$};
\draw[thick,->] (0,-1.5) -- (0,1.5) node[right] {$y$};
\draw[blue,thick,domain=-1.5:1.5] plot (\x,{\x}) node[above] {$y=\cos(x)$};
\end{tikzpicture}
}
%
\subfigure
{
\begin{tikzpicture}[smooth,scale=0.8]
\draw[thick,->] (-2,0) -- (2,0) node[below] {$x$};
\draw[thick,->] (0,-1.5) -- (0,1.5) node[right] {$y$};
\draw[blue,thick,domain=-1.5:1.5] plot (\x,{\x}) node[above] {$y=\tg(x)$};
\end{tikzpicture}
}
%
\subfigure
{
\begin{tikzpicture}[smooth,scale=0.8]
\draw[thick,->] (-2,0) -- (2,0) node[below] {$x$};
\draw[thick,->] (0,-1.5) -- (0,1.5) node[right] {$y$};
\draw[blue,thick,domain=-1.5:1.5] plot (\x,{\x}) node[above]    {$y=\cotg(x)$};
\end{tikzpicture}
}
%
\subfigure
{
\begin{tikzpicture}[smooth,scale=0.8]
\draw[thick,->] (-2,0) -- (2,0) node[below] {$x$};
\draw[thick,->] (0,-1.5) -- (0,1.5) node[right] {$y$};
\draw[blue,thick,domain=-1.5:1.5] plot (\x,{\x}) node[above]    {$y=\arcsin(x)$};
\end{tikzpicture}
}
%
\subfigure
{
\begin{tikzpicture}[smooth,scale=0.8]
\draw[thick,->] (-2,0) -- (2,0) node[below] {$x$};
\draw[thick,->] (0,-1.5) -- (0,1.5) node[right] {$y$};
\draw[blue,thick,domain=-1.5:1.5] plot (\x,{\x}) node[above]    {$y=\arccos(x)$};
\end{tikzpicture}
}
%
\subfigure
{
\begin{tikzpicture}[smooth,scale=0.8]
\draw[thick,->] (-2,0) -- (2,0) node[below] {$x$};
\draw[thick,->] (0,-1.5) -- (0,1.5) node[right] {$y$};
\draw[blue,thick,domain=-1.5:1.5] plot (\x,{\x}) node[above]    {$y=\arctg(x)$};
\end{tikzpicture}
}
%
\subfigure
{
\begin{tikzpicture}[smooth,scale=0.8]
\draw[thick,->] (-2,0) -- (2,0) node[below] {$x$};
\draw[thick,->] (0,-1.5) -- (0,1.5) node[right] {$y$};
\draw[blue,thick,domain=-1.5:1.5] plot (\x,{\x}) node[above]    {$y=\arccotg(x)$};
\end{tikzpicture}
}
\end{figure}
\end{document} • You are having domain issues. If you pick 1/x and search the forum, you will see how to fix your domain problem for plot 5. Then you can use that idea about the domain for the others. NOTE: You have plotted all y = x for the other plots was that intentional due to errors? If not, you are plotting the wrong function for the other plots. – dustin Sep 4 '13 at 22:17
• Here is plot 5: tex.stackexchange.com/questions/20924/… – dustin Sep 4 '13 at 22:22
• Output of this are only axis, not the graph. – goLK Sep 4 '13 at 22:23
• y=x is plotted intentionally because of errors. – goLK Sep 4 '13 at 22:28
• Why don't you use axis and \addplot from pgfplots? This is much more convenient and you will get better results. – Gonzalo Medina Sep 4 '13 at 22:35

## 3 Answers

For this kind of drawings I would suggest you to use pgfplots instead; the inverse trigonometric functions pose a challenge to the PGF math engine, so you can use gnuplot. Here's a big part of your image; the missing elements are easy to fill in:

\documentclass{article}
\usepackage{pgfplots}
\usepackage{subfigure}

\newcommand{\tg}{\mathop{\mathrm{tg}}}
\newcommand{\cotg}{\mathop{\mathrm{cotg}}}
\newcommand{\arctg}{\mathop{\mathrm{arctg}}}
\newcommand{\arccotg}{\mathop{\mathrm{arccotg}}}

\pgfplotsset{
compat=1.8,
every axis plot/.append style={
no marks,
blue,
thick
},
every axis/.style={
enlargelimits=false,
axis lines=middle,
xticklabels=empty,
yticklabels=empty,
xtick=\empty,
ytick=\empty,
width=4.75cm,
xlabel style={at={(rel axis cs:0.94,0.48)},anchor=north west},
ylabel style={at={(rel axis cs:0.5,1.01)},anchor=east},
xlabel=$x$,
ylabel=$y$
},
legend style={
draw=none,
font=\footnotesize\color{blue}
},
every axis legend/.append style={
at={(0.55,1.15)},
anchor=north west
},
empty legend
}

\begin{document}

\begin{figure}
\centering
\subfigure
{%
\begin{tikzpicture}
\begin{axis}[ymin=-1.5,ymax=1.5]
\addplot+[domain=-1.5:1.5] {1};
\addlegendentry{$f(x)=c$}
\end{axis}
\end{tikzpicture}
}
\subfigure%
{
\begin{tikzpicture}
\begin{axis}
\addplot+[domain=-1.5:1.5] {x};
\addlegendentry{$f(x)=x$}
\end{axis}
\end{tikzpicture}
}
%
\subfigure
{
\begin{tikzpicture}
\begin{axis}[ymin=-1.5,ymax=1.5]
\addplot+[domain=-3:3,samples=101] {x^(2)};
\addlegendentry{$f(x)=x^2$}
\end{axis}
\end{tikzpicture}
}\\
%
\subfigure
{
\begin{tikzpicture}
\begin{axis}[ymin=-1.5,ymax=1.5]
\addplot+[domain=-1.5:1.5] {x^(3)};
\addlegendentry{$f(x)=x^3$}
\end{axis}
\end{tikzpicture}
}
%
\subfigure
{
\begin{tikzpicture}
\begin{axis}
\addplot+[domain=-1.5:1.5,unbounded coords=jump,samples=101] {x^(-1)};
\addlegendentry{$f(x)=x^{-1}$}
\end{axis}
\end{tikzpicture}
}
%
\subfigure
{
\begin{tikzpicture}
\begin{axis}[xmin=-1.5,ymin=-1.5,ymax=1.5]
\addplot+[domain=0.0001:1.5,unbounded coords=jump,samples=301] {x^(0.5)};
\addlegendentry{$f(x)=\sqrt{x}$}
\end{axis}
\end{tikzpicture}
}
%
\subfigure
{
\begin{tikzpicture}
\begin{axis}[xmin=-1.5,xmax=1.5,ymin=-1.5,ymax=1.5,enlargelimits=true]
\addplot+[samples=101] {e^(x)};
\addlegendentry{$f(x)=e^{x}$}
\end{axis}
\end{tikzpicture}
}
%
\subfigure
{
\begin{tikzpicture}
\begin{axis}[xmin=-1.5,xmax=1.5,ymin=-1.5,ymax=1.5,enlargelimits=true]
\addplot+[domain=-1.5:1.5,unbounded coords=jump,samples=301] {ln(x)};
\addlegendentry{$f(x)=\ln{x}$}
\end{axis}
\end{tikzpicture}
}
%
\subfigure
{
\begin{tikzpicture}
\begin{axis}[xmin=-6.283,xmax=6.28,ymin=-1.5,ymax=1.5,enlargelimits=true]
\addplot+[] gnuplot [domain=-6.283:6.283,samples=105] {sin(x)};
\addlegendentry{$f(x)=\sin x$}
\end{axis}
\end{tikzpicture}
}\\
%
\subfigure
{
\begin{tikzpicture}
\begin{axis}[xmin=-6.283,xmax=6.28,ymin=-1.5,ymax=1.5,enlargelimits=true]
\addplot+[] gnuplot [domain=-6.283:6.283,samples=105] {cos(x)};
\addlegendentry{$f(x)=\cos x$}
\end{axis}
\end{tikzpicture}
}
%
\subfigure
{
\begin{tikzpicture}
\begin{axis}[xmin=-3.5,xmax=3.5,ymin=-1.5,ymax=1.5,enlargelimits=true]
\addplot+[] gnuplot [domain=-1.5:1.5,unbounded coords=jump,samples=105] {tan(x)};
\addplot+[blue] gnuplot [domain=-3.5:-1.8,unbounded coords=jump,samples=105] {tan(x)};
\addplot+[blue] gnuplot [domain=1.8:3.5,unbounded coords=jump,samples=105] {tan(x)};
\addlegendentry{$f(x)=\tg x$}
\end{axis}
\end{tikzpicture}
}
%
\subfigure
{
\begin{tikzpicture}
\begin{axis}[xmin=-3,xmax=3,ymin=-1.5,ymax=1.5,enlargelimits=true]
\addplot+[domain=-3:-0.1,unbounded coords=jump,samples=101] {cot(deg(x))};
\addplot+[blue,domain=0.1:3,unbounded coords=jump,samples=101] {cot(deg(x))};
\addlegendentry{$f(x)=\cotg x$}
\end{axis}
\end{tikzpicture}
}
%
\subfigure
{
\begin{tikzpicture}
\begin{axis}[xmin=-1,xmax=1,ymin=-1,ymax=1,enlargelimits=true]
\addplot+[] gnuplot [domain=-1:1,unbounded coords=jump,samples=120] {asin(x)};
\addlegendentry{$f(x)=\arcsin x$}
\end{axis}
\end{tikzpicture}
}
%
\subfigure
{
\begin{tikzpicture}
\begin{axis}[xmin=-1,xmax=1,ymin=-3,ymax=3,enlargelimits=true]
\addplot+[] gnuplot [domain=-1:1,unbounded coords=jump,samples=120] {acos(x)};
\addlegendentry{$f(x)=\arccos x$}
\end{axis}
\end{tikzpicture}
}
%
\subfigure
{
\begin{tikzpicture}
\begin{axis}[xmin=-8,xmax=8,ymin=-1.2,ymax=1.2,enlargelimits=true]
\addplot+[] gnuplot [domain=-8:8,unbounded coords=jump,samples=120] {atan(x)};
\addlegendentry{$f(x)=\arctg x$}
\end{axis}
\end{tikzpicture}
}
%
\end{figure}

\end{document} Since gnuplot is being used, you need to have it installed in your system, and the document has to be processed using

pdflatex --shell-escape name.tex


in Lynux systems or something like

pdflatex enable-write18 name.tex


in Windows.

By the way, subfigure is an obsolete package; you should use subfig or subcaption instead.

This is another approach which uses the groupplots library of »pgfplots« to group the plots in some kind of grid. It needs exactly the same prerequisites as Gonzalo's answer.

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage{geometry}
\usepackage{mathtools}
\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}

\DeclareMathOperator{\tg}{tg}
\DeclareMathOperator{\cotg}{cotg}
\DeclareMathOperator{\arctg}{arctg}
\DeclareMathOperator{\arccotg}{arccotg}

\pgfplotsset{compat=newest}

\begin{document}
\begin{tikzpicture}
\begin{groupplot}[
group style={
group size=4 by 4,
vertical sep=1.5cm
},
height=4cm,
width=4cm,
restrict y to domain=-4:4,
samples=100,
axis x line=middle,
axis y line=middle,
xmin=-4,
xmax=4,
xtick=\empty,
ymin=-4,
ymax=4,
ytick=\empty
]
\nextgroupplot[title={$y=c$}]
\addplot[blue,smooth] {1};
\nextgroupplot[title={$y=x$}]
\addplot[blue,smooth] {x};
\nextgroupplot[title={$y=x^2$}]
\addplot[blue,smooth] {x^2};
\nextgroupplot[title={$y=x^3$}]
\addplot[blue,smooth] {x^3};

\nextgroupplot[title={$y=\frac{1}{x}$}]
\addplot[blue,smooth] {1/x};
\nextgroupplot[title={$y=\sqrt{x}$}]
\addplot[blue,smooth,domain=0:4] {sqrt(x)};
\nextgroupplot[title={$y=e^x$}]
\addplot[blue,smooth] {exp(x)};
\nextgroupplot[title={$y=\ln x$}]
\addplot[blue,smooth,domain=0.1:4] {ln(x)};

\nextgroupplot[title={$y=\sin x$}]
\addplot[blue,smooth] {sin(deg(x))};
\nextgroupplot[title={$y=\cos x$}]
\addplot[blue,smooth] {cos(deg(x))};
\nextgroupplot[title={$y=\tg x$}]
\addplot[blue,smooth] {tan(deg(x))};
\nextgroupplot[title={$y=\cotg x$}]
\addplot[blue,smooth] {cot(deg(x))};;

\nextgroupplot[title={$y=\arcsin x$}]
\addplot[blue,smooth] gnuplot[domain=-1:1,unbounded coords=jump] {asin(x)};
\nextgroupplot[title={$y=\arccos x$}]
\addplot[blue,smooth] gnuplot[domain=-1:1,unbounded coords=jump] {acos(x)};
\nextgroupplot[title={$y=\arctg x$}]
\addplot[blue,smooth] gnuplot[domain=-4:4,unbounded coords=jump] {atan(x)};
\nextgroupplot[title={$y=\arccotg x$}]
\addplot[blue,smooth] gnuplot[domain=-4:4,unbounded coords=jump] {pi/2-atan(x)};
\end{groupplot}
\end{tikzpicture}
\end{document}


Modifications to the domains are left to the interested reader. And for didactic purposes, here is a PSTricks version, which doesn't need gnuplot for plotting:

\documentclass{article}
\usepackage[margin=0.5cm]{geometry}
\usepackage{pst-plot}
\colorlet{graphcolor}{blue}
\newpsstyle{Graph}{linecolor=graphcolor, linewidth=2\pslinewidth}
\newpsstyle{legendstyle}{linestyle=none}
\makeatletter
\def\pslegend@iii[#1](#2){\rput[#1](#2){%
\color{graphcolor}\pslegend@text}\gdef\pslegend@text{}}
\makeatother

\newcommand{\tg}{\mathop{\mathrm{tg}}}
\newcommand{\cotg}{\mathop{\mathrm{cotg}}}
\newcommand{\arctg}{\mathop{\mathrm{arctg}}}
\newcommand{\arccotg}{\mathop{\mathrm{arccotg}}}

\thispagestyle{empty}

\begin{document}
\psset{algebraic, labels=none, ticks=none}

\pslegend[tr]{$y = c$}
\begin{psgraph}[arrows=->](0,0)(-1,-1)(1,1){3.5cm}{3.5cm}
\psplot[style=Graph]{-1}{1}{0.7}
\end{psgraph}%
%
\hspace*{1cm}%
%
\pslegend[tr](10,0){$y = x$}
\begin{psgraph}[arrows=->](0,0)(-1,-1)(1,1){3.5cm}{3.5cm}
\psplot[style=Graph]{-1}{1}{x}
\end{psgraph}%
%
\hspace*{1cm}%
%
\pslegend[tr]{$y = x^2$}
\begin{psgraph}[arrows=->](0,0)(-1,-1)(1,1){3.5cm}{3.5cm}
\psplot[style=Graph]{-1}{1}{x^2}
\end{psgraph}

\vspace*{1cm}
\pslegend[tr]{$y = x^3$}
\begin{psgraph}[arrows=->](0,0)(-1,-1)(1,1){3.5cm}{3.5cm}
\psplot[style=Graph]{-1}{1}{x^3}
\end{psgraph}%
%
\hspace*{1cm}%
%
\pslegend[tr]{$y = \frac{1}{x}$}
\begin{psgraph}[arrows=->](0,0)(-5,-5)(5,5){3.5cm}{3.5cm}
\psplot[style=Graph]{0.2}{5}{1/x}
\psplot[style=Graph]{-5}{-0.2}{1/x}
\end{psgraph}%
%
\hspace*{1cm}%
%
\pslegend[tr]{$y = \sqrt{x}$}
\begin{psgraph}[arrows=->](0,0)(-1,-1.5)(1,1.5){3.5cm}{3.5cm}
\psplot[style=Graph]{0}{1}{sqrt(x)}
\end{psgraph}

\vspace*{1cm}
\pslegend[tr]{$y = \mathrm{e}^x$}
\begin{psgraph}[arrows=->](0,0)(-2,-2)(2,2){3.5cm}{3.5cm}
\psplot[style=Graph]{-2}{0.6}{Euler^x}
\end{psgraph}%
%
\hspace*{1cm}%
%
\pslegend[tr]{$y = \ln x$}
\begin{psgraph}[arrows=->](0,0)(-3,-3)(3,3){3.5cm}{3.5cm}
\psplot[style=Graph]{0.1}{3}{ln(x)}
\end{psgraph}%
%
\hspace*{1cm}%
%
\pslegend[tr]{$y = \sin x$}
\begin{psgraph}[arrows=->](0,0)(-\psPiTwo,-1.5)(\psPiTwo,1.5){3.5cm}{3.5cm}
\psplot[style=Graph]{-\psPiTwo}{\psPiTwo}{sin(x)}
\end{psgraph}

\vspace*{1cm}
\pslegend[tr]{$y = \cos x$}
\begin{psgraph}[arrows=->](0,0)(-\psPiTwo,-1.5)(\psPiTwo,1.5){3.5cm}{3.5cm}
\psplot[style=Graph]{-\psPiTwo}{\psPiTwo}{cos(x)}
\end{psgraph}%
%
\hspace*{1cm}%
%
\pslegend[tr]{$y = \tg x$}
\begin{psgraph}[arrows=->](0,0)(-3.5,-3.5)(3.5,3.5){3.5cm}{3.5cm}
\psplot[style=Graph]{-3.5}{-1.93}{tan(x)}
\psplot[style=Graph]{-1.2}{1.2}{tan(x)}
\psplot[style=Graph]{1.93}{3.5}{tan(x)}

\end{psgraph}%
%
\hspace*{1cm}%
%
\pslegend[tr]{$y = \cotg x$}
\begin{psgraph}[arrows=->](0,0)(-\psPi,-5)(\psPi,5){3.5cm}{3.5cm}
\psplot[style=Graph]{-2.88}{-0.26}{1/tan(x)}
\psplot[style=Graph]{0.26}{2.88}{1/tan(x)}
\end{psgraph}

\vspace*{1cm}
\pslegend[tr](-10,0){$y = \arcsin x$}
\begin{psgraph}[arrows=->](0,0)(-1,-2)(1,2){3.5cm}{3.5cm}
\psplot[style=Graph, plotpoints=500]{-1}{1}{asin(x)}
\end{psgraph}%
%
\hspace*{1cm}%
%
\pslegend[tr](-5,0){$y = \arccos x$}
\begin{psgraph}[arrows=->](0,0)(-1,-4)(1,4){3.5cm}{3.5cm}
\psplot[style=Graph, plotpoints=500]{-1}{1}{acos(x)}
\end{psgraph}%

\vspace*{1cm}%
%
\pslegend[tr](-5,0){$y = \arctg x$}
\begin{psgraph}[arrows=->](0,0)(-3,-3.5)(3,3.5){3.5cm}{3.5cm}
\psplot[style=Graph]{-3}{3}{atg(x)}
\end{psgraph}%
%
\hspace*{1cm}%
%
\pslegend[tr](-5,0){$y = \arccotg x$}
\begin{psgraph}[arrows=->](0,0)(-3,-3.5)(3,3.5){3.5cm}{3.5cm}
\psplot[style=Graph]{-3}{3}{PiDiv2-atg(x)}
\end{psgraph}
\end{document} 