I defined an area bounded by four functions. I found related answers like:
"filling area between 2 functions, with shading", but I am not able to adapt this. solution.
Here the example:
% !TEX program = pdflatex
% !TEX encoding = UTF-8 Unicode
\documentclass{standalone}
\usepackage{pgfplots}
\usepackage{amsmath}
\begin{document}
\begin{tikzpicture}
\begin{axis}[axis equal image,
width=10cm,
axis lines=middle,
axis line style={-latex},
clip =false,
xmin=0,xmax=2.45,
ymin=0,
no markers,
xlabel={$x$},ylabel={$y$},
every axis x label/.append style={anchor=north},
every axis y label/.append style={anchor=east},
]
\addplot[domain=0.4:1.2,thick] { 1/x } node[anchor=135] {$f(x)=\dfrac{1}{x}$};
\addplot[domain=.6:2,thick] { 2/x } node[right] {$f(x)=\dfrac{2}{x}$};
\addplot[domain=0.7:1.5,thick] { x } node[right] {$f(x)=x$};
\addplot[domain=0.4:.8,thick] { 4*x } node[right] {$f(x)=4x$};
%\addplot+[domain=0.5:1] { 1/x };
%\addplot+[domain=1:sqrt(2)] { x };
%\addplot+[domain=1/sqrt(2):sqrt(2)] { 2/x };
%\addplot+[domain=0.5:1/sqrt(2)] { 4*x };
\end{axis}
\end{tikzpicture}
\end{document}
With the result:
I want to fill the area with vertical lines or maybe simple gray.
Best Answer
I found a way.
The environment needs the option
area style
to draw correct axis.Now I draw every function again with the command closedcycle where the functions above are filled with gray and the functions below fill with white. (draw over).