3

I have a problem with pgfplots and it took me a while to strip down my problem to the minimum. I try to add two lines and fill the area between them. The curves have points outside of the axis area. With 'compat=newest' this results in a figure too big. With 'compat=default' the figure is clipped right at the axes.

The followig MWE shows the problem:

\documentclass{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}

\pgfplotsset{compat=newest}

\begin{document}
    \begin{tikzpicture}
        \begin{axis}[
            xmin=-90,
            xmax=90,
            ymin=-90,
            ymax=90,
            ]
            \addplot[name path=A] table{
                -90     -80
                90      100
                };
            \addplot[name path=B] table{
                -90     -100
                90      80
                };
            \addplot fill between[of=A and B];
        \end{axis}
    \end{tikzpicture}
\end{document}

I tried to add some sample images, but with the white background you cannot tell the difference here. I keep trying to get feasible samples.

In this example the figure gets just slightly bigger, than expected. But in my actual file it gains about 50% in height resulting in very akward spacing. For now I solve the problem with compat=default. Is there any other solution? Thank you very much in advance.

Gunter
  • 443
  • hmmm i put your mwe into sharelatex and i don't see a difference between compat=newest and compat=default. am i missing something? – aeroNotAuto Mar 12 '15 at 12:48
  • As recommended by the author of pgfplots, you should pick an explicit version, instead of using the default and newest options. In fact, if you look at the log file for the default, you'll find that it recommends you to add an explicit version. I can reproduce this behavior you see, but I think it is "expected" :-) There is probably some way to fix it, let's see – darthbith Mar 12 '15 at 12:56
  • Yes, I saw the log entry, when using default. That's why I went using newest a long time ago. I never noticed a difference. But now I actually stumbled over a version issue. So I should reconsider and put a specific version there. – Gunter Mar 13 '15 at 07:29

1 Answers1

3

This is the expected behavior since version 1.8. We can "fix" it by setting the clip bounding box key, described on page 325 of the v 1.12 manual. Prior to version 1.8, the default value for this key was default tikz, which clipped the bounding box to the axes. Now, the default is upper bound, which changes the behavior as you see. The keyword compat=default introduces version pre 1.3 (explained on page 11 of the v 1.12 manual), so uses the old behavior. We can restore the old behavior by simply setting the value of the appropriate key in pgfplotsset:

\documentclass{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}

\pgfplotsset{compat=1.12, clip bounding box=default tikz}

\begin{document}
    \begin{tikzpicture}
        \begin{axis}[
            xmin=-90,
            xmax=90,
            ymin=-90,
            ymax=90,
            ]
            \addplot[name path=A] table{
                -90     -80
                90      100
                };
            \addplot[name path=B] table{
                -90     -100
                90      80
                };
            \addplot fill between[of=A and B];
        \end{axis}
    \end{tikzpicture}
\end{document}

enter image description here

darthbith
  • 7,384
  • Thank you very much. It worked very well. It seems, that everything is contained in the pgfplots documentation. You just need to know, what you are looking for. I need to read the section about the clip bounding box again. By now I have not yet understood the advantages of upper bound. – Gunter Mar 13 '15 at 07:31