I am trying to plot functions and shade in between them. Here is the code:
\documentclass[a4paper, 12pt]{article}
\usepackage[dvipsnames]{xcolor}
\usepackage{amsmath}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}
\usepgfplotslibrary{fillbetween}
% I included the formatting stuff as well
\usepackage{fancyhdr}
\usepackage[a4paper, portrait, margin=1in]{geometry}
\pagestyle{fancy}
\fancyhf{}
\rhead{October 18, 2018}
\lhead{Tutoring Notes}
\rfoot{\thepage}
\begin{document}
\begin{figure}[ht]
\centering
\begin{tikzpicture}[scale=1.75,line width=1pt]
\begin{axis}[
color= gray,
xmin=-4.9,
xmax=4.9,
ymin=-1.9,
ymax=2.9,
axis equal image,
axis lines=middle,
font=\scriptsize,
xtick distance=1,
ytick distance=1,
xticklabels={},
yticklabels={},
legend pos=outer north east,
inner axis line style={stealth-stealth}
]
\addplot[red, smooth, domain=-4.9:4.9, name path=1] {(8)/(4 + x^2)};
\addlegendentry[black]{$f(x)$}
\addplot[blue, smooth, domain=-4.9:4.9, name path=2]{(-16*x)/((4+x^2)^2)};
\addlegendentry[black]{$f'(x)$}
\addplot[green, smooth, domain=-4.9:4.9, name path=3]{-(((16)*((4 +
x^2)^2))-((4 + x^2)*(64*(x^2))))/((4+x^2)^4)};
\addlegendentry[black]{$f''(x)$}
%\addplot[red, fill opacity=0.20] fill between [of=1 and 2,soft clip=
{domain=2:4}];
\draw[black] (0,1) circle [radius=1];
\end{axis}
\end{tikzpicture}
\caption{Plotting the curve when $r=1$.}
\label{fig:1}
\end{figure}
\end{document}
And when the one line is commented out, I get a graph in the desired location (this is part of a bigger document):
However, when I uncomment the plot command that is meant to shade in a region between two of the curves, there is a huge skip in the document and the legend disappears:
Why is this happening? This happens when I plot other functions as well, and I do not know why.


