Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
    
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 1

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}
share|improve this answer
    
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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.