# [Tex/LaTex] Graphing an exponential function and its inverse on the same Cartesian plane

tikz-pgf

I would like to graph an exponential function and its inverse on the same Cartesian plane using TikZ (or pgfplots). I have code using TikZ. Apparently, there is an error in the \addplot command.

I would like to plot y = 2^{x} and y = \log_{2}(x). (The code is for e^{x} and \ln(x). I was not sure how to enter "\log_{2}(x)" in TikZ.) The exponential function should be labeled "y = 2^{x}" towards the top, where its graph ends, and the logarithmic function should be labeled "y = \log_{2}(x)" towards the bottom, where its graph ends.

\documentclass[10pt]{amsart}
\usepackage{tikz}
\usetikzlibrary{calc,angles,positioning,intersections,quotes,decorations.markings}
\usepackage{tkz-euclide}
\usetkzobj{all}

\begin{document}

\begin{tikzpicture}[dot/.style={draw,fill,circle,inner sep=1pt}]
\draw[<->] (-7,0) -- (7,0) node[below]{$x$};
\draw[<->] (0,-7) -- (0,7) node[left]{$y$};
\draw[<->, dashed] (-6.5,-6.5) -- (6.5,6.5) node[right]{$y=x$};
\end{tikzpicture}

\end{document}


Here is a quick example;

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}
\begin{document}
\begin{tikzpicture}
\begin{axis}[grid=both,
xmax=10,ymax=10,
axis lines=middle,
restrict y to domain=-7:12,
enlargelimits]
\addplot[green]  {pow(2,x)} node[above]{$y=2^x$};
\addplot[blue,domain=1/2^6:10,samples=100]  {log2(x)} node[above left] {$y=\log_2(x)$};
\end{axis}
\end{tikzpicture}
\end{document} 