2

With the following:

events.dat

y mean lower upper
0 7.70234e-08 6.73448e-08 8.67019e-08
0.1 8.49244e-08 7.72264e-08 9.26225e-08
0.2 1.1735e-07 1.02559e-07 1.32141e-07
0.3 3.06841e-07 2.47066e-07 3.66616e-07
0.4 1.59601e-06 1.36706e-06 1.82496e-06
0.5 5.95445e-06 4.11006e-06 7.79884e-06
0.6 -5.19059e-06 -1.05236e-05 1.42373e-07
0.7 -6.53589e-05 -9.47471e-05 -3.59706e-05
0.8 -0.000211282 -0.000255298 -0.000167265
0.9 -0.00041731 -0.000518634 -0.000315985
1 -0.000812216 -0.000998166 -0.000626266

main.tex

\documentclass[12pt]{article}
\usepackage{tikz, pgfplots}
\pgfplotsset{compat=1.10}
\usepgfplotslibrary{fillbetween}
\begin{document}
    \begin{figure}
        \begin{tikzpicture}[baseline]
            \begin{axis}[
                    width=0.5\textwidth,
                    height=0.5\textwidth,
                    xlabel=X,
                    ylabel=Y,
                    title=This is a title,
                    ymin=-0.0003,
                    ymax=0.000012,
                ]
                \addplot[
                    red,
                    name path=max,
                ] table[
                    x=y,
                    y=upper,
                ] {events.dat};
                \addplot[
                    green,
                    name path=min,
                ] table[
                    x=y,
                    y=lower,
                ] {events.dat};
                \addplot[
                    blue,
                    opacity=0.1,
                ] fill between[of=min and max];
            \end{axis}
            \draw (current bounding box.south east) rectangle (current bounding box.north west);
        \end{tikzpicture}%
    \end{figure}
\end{document} 

With the ymin and ymax lines commented it is fine. Then with these in play, and with smaller and smaller values for ymin, for example, -0.0006, -0.0005, -0.0004, and -0.0003, the plot moves down the page, with -0.0001 finally pushing it off the bottom of the page. Why? I want to have <= -0.0001 and still have the plot on the page!

Furthermore, suggested by a comment if you draw the bounding box one can see the stretching:

bounding box stretched

  • 2
    Curious. If you add \draw (current bounding box.south east) rectangle (current bounding box.north west); at the end of the tikzpicture environment you'll see that the bounding box is obviously calculated wrongly. Why that happens though, I cannot say. – Torbjørn T. Nov 30 '15 at 7:53
  • Seems like an issue with the fill between library: If you remove the last addplot which applies the fill between then the excess vertical spacing goes away. – Peter Grill Nov 30 '15 at 10:22
2

It's because the actual box size is reported due to the following (after adding clip=false to the axis)

enter image description here

This is the vertical box saved but then since it is clipped it is placed at the baseline. You can add restrict y to domain=-5e-4:0.1 to restrict this drawing and it would get better.

Probably the fill between doesn't yet respect the clipping but still thinks it has the full visible context. It might be a bug or a quirk. So another one for Christian Feuersänger.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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