# Shading a strip between two intersection points of the curve with the axis

I wish to shade a small strip along the x-axis where the graph of a curve intersects the axis. I have used the following code

\documentclass[12pt]{standalone}

\usepackage{pgfplots}
\usetikzlibrary{patterns,intersections,calc}

\begin{document}
\begin{tikzpicture}
\begin{axis}[axis x line = middle, axis y line = center, ymin=-3,
xmin=-7, xmax=7,
xtick=\empty, ytick = \empty]
\addplot[smooth, name path=parabola] {x^2-2};
\path[name path=axis] (axis cs:-7,0) -- (axis cs:7,0);
\fill [name intersections={of=parabola and axis,by={a,b}}] (a)
circle (2pt)(b) circle (2pt);
\fill[pattern=north west lines] (a) -- (b) -- ++ (axis direction
cs:0,-0.4) -- cycle;
\fill[pattern=north west lines] (b) -- (a) -- ++ (axis direction
cs:0,-0.4) -- cycle;
\end{axis}
\end{tikzpicture}
\end{document}


The reason why I have used two fill statements is that in the first statement I am unable to figure how to specify the axis direction cs vector in the negative direction from b to a. Is there a way to do it?

-
Welcome to TeX.SX! I don't know if I understand correctly your question but you could calculate the point below (a) with the calc library. Do you want a rectangular shape? –  bersanri Jun 21 '13 at 8:15

## 1 Answer

You can simply use the -| path statement to get back to (a):

\documentclass[12pt]{standalone}

\usepackage{pgfplots}
\usetikzlibrary{patterns,intersections,calc}

\begin{document}
\begin{tikzpicture}
\begin{axis}[axis x line = middle, axis y line = center, ymin=-3,
xmin=-7, xmax=7,
xtick=\empty, ytick = \empty]
\addplot[smooth, name path=parabola] {x^2-2};
\path[name path=axis] (axis cs:-7,0) -- (axis cs:7,0);
\fill [name intersections={of=parabola and axis,by={a,b}}] (a)
circle (2pt)(b) circle (2pt);
\fill[pattern=north west lines] (b) -- ++ (axis direction
cs:0,-0.4) -| (a);
\end{axis}
\end{tikzpicture}
\end{document}

-
Thanks, I got the same idea an hour ago ... However is it possible to have the access to coordinates of the point below 'b' 0.4 'axis units' on the path –  Abhishek Jun 21 '13 at 15:04
@Abhishek: Sure: ([shift={(axis direction cs:0,-0.4)}]b) refers to that point. –  Jake Jun 21 '13 at 15:06