2

This post is continuation of the discussion starting in the comment to the following post post

The following code works perfectly fine, but if I change to compat = 1.10 shading disappears. I am curious why? Also commenting %\pgfplotsset{compat=1.11} removes shading.

\documentclass{article}

\usepackage{pgfplots}
\pgfplotsset{compat=1.11}
\usepgfplotslibrary{fillbetween}
\usetikzlibrary{patterns}

\begin{document}


  \begin{tikzpicture}
    \begin{axis}[
        xmin=-1, xmax=3,
        ymin=-1, ymax=3,
        axis lines=middle,
      ]  
      \addplot [gray, name path = A] coordinates {(0, 1) (1, 1)};

      \path[name path=xaxis] (\pgfkeysvalueof{/pgfplots/xmin}, 0) -- (\pgfkeysvalueof{/pgfplots/xmax},0);

      \addplot[gray, pattern=north west lines] fill between[of=A and xaxis, soft clip={domain=1/2:1}];

    \end{axis}
  \end{tikzpicture}


\end{document}

1 Answers1

4

As I mentioned in my final comment, with compat=1.11 a coordinate used with \draw (and also the other "normal" TikZ drawing commands, including \path), will be assumed to be in axis coordinates. With 1.10 it will not be.

Hence, in \path[name path=xaxis] (\pgfkeysvalueof{/pgfplots/xmin}, 0) -- (\pgfkeysvalueof{/pgfplots/xmax},0); the path doesn't actually run along the x-axis if you have compat=1.10 or no compat setting at all.

If you change to

\path[name path=xaxis] (axis cs:\pgfkeysvalueof{/pgfplots/xmin}, 0) -- (axis cs:\pgfkeysvalueof{/pgfplots/xmax},0);

the switch to the axis coordinate system is explicit, and it will work as expected regardless of compat setting.

Below is a complete example demonstrating the difference. A blue line is drawn with axis cs, a red line without. You can see the red line in the bottom left of this screenshot.

enter image description here

\documentclass{article}
\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}
\usetikzlibrary{patterns}

\begin{document}


  \begin{tikzpicture}
    \begin{axis}[
        xmin=-1, xmax=3,
        ymin=-1, ymax=3,
        axis lines=middle,
        clip=false % added just for this example
      ]  
      \addplot [gray, name path = A] coordinates {(0, 1) (1, 1)};

      % here we use axis cs:, so it works
      \draw[blue, ultra thick, name path=xaxis] (axis cs:\pgfkeysvalueof{/pgfplots/xmin}, 0) -- (axis cs:\pgfkeysvalueof{/pgfplots/xmax},0);

      % here we don't, so it doesn't work (in the way you expected)
      \draw[red, ultra thick] (\pgfkeysvalueof{/pgfplots/xmin}, 0) -- (\pgfkeysvalueof{/pgfplots/xmax},0);


      \addplot[gray, pattern=north west lines] fill between[of=A and xaxis, soft clip={domain=1/2:1}];

    \end{axis}
  \end{tikzpicture}

\end{document}
Torbjørn T.
  • 206,688