# To Shade the Area Between $x^2$ and $\sqrt{x}$

I want to draw the following image in tikZ

Basically I want to draw the boundary of the unit square, plot the x^2 and \sqrt x functions, and shade the area between them.

In my attempt to draw the two curves, I tried this

\documentclass[border=5mm]{standalone}

\usepackage{pgfplots}
\pgfplotsset{compat=1.10}
\usepgfplotslibrary{fillbetween}
\usetikzlibrary{patterns}
\pgfplotsset{ticks=none}

\begin{document}
\begin{tikzpicture}
\begin{axis}[axis lines=middle,]
\end{axis}
\end{tikzpicture}
\end{document}


But the output I am getting is

Somehow the \sqrt{x} function is getting flattened out.

Also, how to get rid of the arrows I have in the axes and make an enclosing box like I have in the hand-drawn picture.

• Note that the intersection of curves happens for x=1. So change domain to better visualize. – Sigur Jun 23 '18 at 14:17
• Welcome to TeX.SX! Please make your code compilable (if possible), or at least complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem. – dexteritas Jun 23 '18 at 14:18
• sqrt x should propbably be sqrt(x) – user121799 Jun 23 '18 at 14:27
• @marmot That does not make any difference. – dexteritas Jun 23 '18 at 14:33
• @dexteritas I did not know about the etiquette you mentioned. But it makes a lot of sense. Thanks. I have edited my post. – caffeinemachine Jun 23 '18 at 14:35

• Set min=0,xmax=1,ymin=0,ymax=1 to get the desired area of the plots.
• Remove axis lines=middle to get default axis (rectangle around plots).
• Use \addplot [fill=blue!10] fill between[of=F and G]; to fill area between plots F and G.

Code:

\documentclass[border=5mm]{standalone}

\usepackage{pgfplots}
\pgfplotsset{compat=1.10}
\usepgfplotslibrary{fillbetween}
\usetikzlibrary{patterns}
\pgfplotsset{ticks=none}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
xmin=0,xmax=1,
ymin=0,ymax=1,
samples=500,
]
\addplot [fill=blue!10] fill between[of=F and G];
\end{axis}
\end{tikzpicture}

\end{document}


Result:

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\usepgfplotslibrary{fillbetween}
\usetikzlibrary{patterns}
\begin{document}
\pgfplotsset{ticks=none}

\begin{tikzpicture}
\begin{axis}[axis lines=middle,]