删除绘图空白标签周围的空白区域

删除绘图空白标签周围的空白区域

我有以下 MWE

%!TEX program=lualatex
\documentclass[crop,tikz]{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}
\pgfplotsset{
    compat=1.16,
}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
    xtick=\empty,
    xticklabels=\empty,
    ytick=\empty,
    yticklabels=\empty,
]
\end{axis}
\end{tikzpicture}
\begin{tikzpicture}
\begin{groupplot}[
    group style = {
        group size = 2 by 1,
        x descriptions at = edge bottom,
        y descriptions at = edge left,
    },
    xtick=\empty,
    xticklabels=\empty,
]
\nextgroupplot[
    axis y line* = left,
]

\nextgroupplot[
    axis y line* = right,
]
\end{groupplot}
\end{tikzpicture}
\end{document}

应该没有刻度和标签(第一个图)。但是,它在 x 和 y 标签的位置留下了一个空白边距。我想修剪这个边距,就像顶部和右侧边距一样。我该怎么做?

Result

我的实际目标是得到类似第二幅图的东西。我只在左侧图上保留标签y descriptions at = edge left,并删除中间轴以突出显示数据的连续性。这里我在右侧有空白边距(并且,在此示例中,也在底部,但那里会有标签)。

答案1

使用负长度进行border={<left> <bottom> <right> <top>}修剪。我称这种方法为“野蛮方法”。

\documentclass[border={-6.5pt -6.5ptpt 0pt 0pt},tikz]{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}
\pgfplotsset{
    compat=1.16,
}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
    xtick=\empty,
    xticklabels=\empty,
    ytick=\empty,
    yticklabels=\empty,
]
\end{axis}
\end{tikzpicture}
\begin{tikzpicture}
\begin{groupplot}[
    group style = {
        group size = 2 by 1,
        x descriptions at = edge bottom,
        y descriptions at = edge left,
    },
    xtick=\empty,
    xticklabels=\empty,
]
\nextgroupplot[
    axis y line* = left,
]

\nextgroupplot[
    axis y line* = right,
]
\end{groupplot}
\end{tikzpicture}
\end{document}

enter image description here

答案2

如果你真的如果你想这样做,你可以直接把空节点从边界框中取出来。最快的方法很残酷:

\tikzset{every node/.append style={overlay}}

要让特定节点对边界框做出贡献,你可以说例如

yticklabel style={overlay=false},

加上trims 就可以得到

\documentclass[crop,tikz]{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}
\pgfplotsset{
    compat=1.16,
}
\begin{document}
\begin{tikzpicture}[trim axis left,every node/.append style={overlay}]
\begin{axis}[
    xtick=\empty,
    xticklabels=\empty,
    ytick=\empty,
    yticklabels=\empty,
]
\end{axis}
\end{tikzpicture}
\begin{tikzpicture}[every node/.append style={overlay},trim axis group right]
\begin{groupplot}[yticklabel style={overlay=false},
    group style = {
        group size = 2 by 1,
        x descriptions at = edge bottom,
        y descriptions at = edge left,
    },
    xtick=\empty,
    xticklabels=\empty,
]
\nextgroupplot[
    axis y line* = left,
]

\nextgroupplot[
    axis y line* = right,
]
\end{groupplot}

\end{tikzpicture}
\end{document}

enter image description here

相关内容