I would like to clip along a \addplot
line made by pgfplots
. I am not sure entirely how to do this since my tries have failed. What have done so far is below.
\documentclass[tikz, convert = false]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat = 1.10}
\usetikzlibrary{intersections}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
no marks,
axis x line = center,
axis y line = center,
xmin = 0,
xmax = 5,
xlabel = {x},
ylabel = {y}
]
\addplot[blue, samples = 500, smooth, name path global = pinvx]
gnuplot[domain = .5:5] {1/x};
\addplot[red, samples = 500, smooth, name path global = ninvx]
gnuplot[domain = .5:5] {-1/x};
\legend{$\frac{1}{x}$, $\frac{-1}{x}$}
\path[name path = line1] (axis cs:1.6, 1) -- (axis cs:1.6, -1);
\path[name path = line2] (axis cs:1.75, 1) -- (axis cs:1.75, -1);
\path[name intersections = {of = pinvx and line1, by = P1}];
\path[name intersections = {of = ninvx and line1, by = P2}];
\path[name intersections = {of = pinvx and line2, by = P3}];
\path[name intersections = {of = ninvx and line2, by = P4}];
\draw[green, opacity =.7] (P1) -- (P2);
\draw[green, opacity =.7] (P3) -- (P4);
\begin{scope}
\clip pinvx;
\fill[green, opacity =.7] (P1) -- (P3) -- (1.75, 0) -- (1.6, 0);
\end{scope}
\end{axis}
\end{tikzpicture}
\end{document}
My end goal is to fill the area between the lines and the 1/x
and -1/x
plots. I tried using clip with the first plot name but that doesn't work.
Here is the plot with out the attempt of shading the area.
fillbetween
. – Henri Menke Apr 22 '14 at 15:45fillbetween
. – Henri Menke Apr 22 '14 at 17:43