设置图层和 useasboundingbox 之间的冲突

设置图层和 useasboundingbox 之间的冲突

我正在使用extra ticks并希望在轴后面绘制额外的刻度(像所有其他刻度一样)。因此,我使用\pgfplotsset{set layers}。但是,此选项显然与命令不兼容\useasboundingbox,因为我收到错误消息! Dimension too large. \pgfplotspointupperrightcorner ...f@x =-32000.0pt

有没有简单的解决方法来结合这两个命令?如果没有,我该如何删除图周围的多余空白?

图像在 1.1 处有额外的 y 刻度(并且在轴线后面有刻度),但周围有太多空白: 图像有多余的勾号但周围有太多空白

无图层和有图层的图像(缩放):

无图层的图像 带图层的图像(缩放)

梅威瑟:

\documentclass{standalone}
\usepackage{tikz,pgfplots}
\pgfplotsset{compat=1.13}
\begin{document}

\pgfplotsset{set layers}% <-- conflict with useasboundigbox, needed that extra y ticks are behind axis line
\begin{tikzpicture}
%\useasboundingbox (-0.65,-0.45) rectangle (6.85,5.85); % <-- conflict with set layers, needed to reduce extra space around plot

\begin{axis}[
    axis x line=bottom,
    axis y line=left,
    extra y ticks={1.1},
    ]
    \addplot[black] coordinates {(0,2) (1,1) (2.2,2)};  
\end{axis}
\end{tikzpicture}
\end{document}

答案1

我不知道您的代码中为什么会有冲突。但这里有两个针对您的示例的解决方法。

您可以替换\useasboundingbox并将path放在环境axispgfinterruptboundingbox

\documentclass{standalone}
\usepackage{pgfplots}% loads also tikz
\pgfplotsset{compat=1.14}
\begin{document}
\pgfplotsset{set layers}
\begin{tikzpicture}
    \path (-0.65,-0.45) rectangle (6.85,5.85);% \path instead \useasboundingbox
    \begin{pgfinterruptboundingbox}% <-added
        \begin{axis}[
            axis x line=bottom,
            axis y line=left,
            extra y ticks={1.1},
            ]
            \addplot[black] coordinates {(0,2) (1,1) (2.2,2)};  
        \end{axis}
    \end{pgfinterruptboundingbox}% <- added
\end{tikzpicture}
\end{document}

axis或者你改变环境和命令的顺序\useasboundingbox。但你必须添加一个\pgfresetboundingbox命令 \useasboundingbox

\documentclass{standalone}
\usepackage{pgfplots}% loads also tikz
\pgfplotsset{compat=1.14}
\begin{document}
\pgfplotsset{set layers}
\begin{tikzpicture}
    \begin{axis}[
        axis x line=bottom,
        axis y line=left,
        extra y ticks={1.1},
        ]
        \addplot[black] coordinates {(0,2) (1,1) (2.2,2)};  
    \end{axis}
    \pgfresetboundingbox% <- added
    \useasboundingbox (-0.65,-0.45) rectangle (6.85,5.85);% behind axis and \pgfresetboundingbox
\end{tikzpicture}
\end{document}

相关内容