当 `useasboundingbox` 与 `fill between` 一起使用时,出现“尺寸太大”

当 `useasboundingbox` 与 `fill between` 一起使用时,出现“尺寸太大”
\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}
\pgfplotsset{compat=newest}
\begin{filecontents*}{data.txt}
    X   Y       CI95
    1   1.50    0.39
    2   1.05    0.21
    3   0.50    0.14
    4   0.20    0.05
    5   0.35    0.35
\end{filecontents*}
\begin{document}

\begin{tikzpicture}
\useasboundingbox (-0.5,-0.5) rectangle (5.0,5.0);
\begin{axis}[
]
\addplot [name path=lower] table [x=X,y expr=\thisrow {Y} - \thisrow {CI95}
]{data.txt};
\addplot [name path=upper] table [x=X, y expr=\thisrow{Y} + \thisrow{CI95}]{data.txt};
\addplot[green!40] fill between[of=lower and upper];

\end{axis}
\end{tikzpicture}

输出正确:

在此处输入图片描述

但日志中有错误:

! Dimension too large.
\pgfplotspointupperrightcorner ...f@x =-32000.0pt 
                                                  \global \pgf@y =-32000.0pt 
l.25 \end{axis}
               
I can't work with sizes bigger than about 19 feet.
Continue and I'll use the largest value I can.

! Dimension too large.
\pgfplotspointupperrightcorner ...f@y =-32000.0pt 
                                                  
l.25 \end{axis}
               
I can't work with sizes bigger than about 19 feet.
Continue and I'll use the largest value I can.

答案1

您可以在最后重置边界框,然后再设置它,而不是在开始时设置它。这样可以避免您提到的错误。通常,这是更好的选择,因为这可以让您毫无问题地测量事物,例如使用local bounding box

\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}
\pgfplotsset{compat=newest}
\begin{filecontents*}[overwrite]{data.txt}
    X   Y       CI95
    1   1.50    0.39
    2   1.05    0.21
    3   0.50    0.14
    4   0.20    0.05
    5   0.35    0.35
\end{filecontents*}
\begin{document}

\begin{tikzpicture}
\begin{axis}[
]
\addplot [name path=lower] table [x=X,y expr=\thisrow {Y} - \thisrow {CI95}
]{data.txt};
\addplot [name path=upper] table [x=X, y expr=\thisrow{Y} + \thisrow{CI95}]{data.txt};
\addplot[green!40] fill between[of=lower and upper];
\end{axis}
\pgfresetboundingbox
\path[use as bounding box] (-0.5,-0.5) rectangle (5.0,5.0);
\end{tikzpicture}
\end{document}

相关内容