在某些绘图上启用 xticks 的表格会移动一个绘图

在某些绘图上启用 xticks 的表格会移动一个绘图

我有 4 个使用表格排列的图:

resulting document

\documentclass{scrartcl}

\usepackage{pgfplots}
\pgfplotsset{compat=1.16}

\begin{document}

\pgfplotsset{
  height=4cm, width=\linewidth*0.5,
  every axis plot post/.append style={mark=none},
  xmin=-1, xmax=1, domain=-1:1, samples=100, minor y tick num=1,
  xtick=\empty
}

\begin{tabular}{rl}
  \begin{tikzpicture}[baseline,trim axis left]
    \begin{axis}[title=Gaussian,
      legend entries={$s=2$, $s=4$,$s=8$}]
      \addplot {exp(- (2*x)^2)};
      \addplot {exp(- (4*x)^2)};
      \addplot {exp(- (8*x)^2)};
    \end{axis}
  \end{tikzpicture}
  &
    \begin{tikzpicture}[baseline,trim axis right]
      \begin{axis}[title=Volume Splines]
        \addplot {abs(x)};
      \end{axis}
    \end{tikzpicture}
  \\
  \begin{tikzpicture}[baseline,trim axis left]
    \begin{axis}[title=Multi Quadrics,
      legend entries={$s=2$, $s=4$,$s=6$},
      xtick={}]
      \addplot {sqrt(2^2 + x^2)};
      \addplot {sqrt(4^2 + x^2)};
      \addplot {sqrt(6^2 + x^2)};
    \end{axis}
  \end{tikzpicture}
  &
    \begin{tikzpicture}[baseline,trim axis right]
      \begin{axis}[title=Inverse Multi Quadrics,
        legend entries={$s=1$, $s=2$,$s=3$},
        xtick={}]
        \addplot {1/sqrt(1^2 + x^2)};
        \addplot {1/sqrt(2^2 + x^2)};
        \addplot {1/sqrt(3^2 + x^2)};
      \end{axis}
    \end{tikzpicture}
\end{tabular}

\end{document}

如您所见,左下角的图略微向左移动。我该如何修复它?

为什么我不使用groupplots?如您所见,我希望每个图都有不同的图例。据我所知,这在 中是不可能的groupplots

为什么我不使用matrix?根据 pgfplots 文档 4.19.4 和矩阵,您需要使用legend to name

如果使用另外两种方法中的任何一种都可以实现,我很乐意接受纠正。

谢谢!

答案1

groupplot 库就是为此而创建的。

\documentclass{scrartcl}

\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\usepgfplotslibrary{groupplots} 

\begin{document}

\pgfplotsset{
  height=4cm, width=\linewidth*0.5,
  every axis plot post/.append style={mark=none},
  xmin=-1, xmax=1, domain=-1:1, samples=100, minor y tick num=1,
  xtick=\empty
}
\begin{tikzpicture}
\begin{groupplot}[group style={group size=2 by 2},height=4cm, width=\linewidth*0.5,]
    \nextgroupplot[title=Gaussian,
      legend entries={$s=2$, $s=4$,$s=8$}]
      \addplot {exp(- (2*x)^2)};
      \addplot {exp(- (4*x)^2)};
      \addplot {exp(- (8*x)^2)};
     \nextgroupplot[title=Volume Splines]
        \addplot {abs(x)};
     \nextgroupplot[title=Multi Quadrics,
      legend entries={$s=2$, $s=4$,$s=6$},
      xtick={}]
      \addplot {sqrt(2^2 + x^2)};
      \addplot {sqrt(4^2 + x^2)};
      \addplot {sqrt(6^2 + x^2)};
     \nextgroupplot[title=Inverse Multi Quadrics,
        legend entries={$s=1$, $s=2$,$s=3$},
        xtick={}]
        \addplot {1/sqrt(1^2 + x^2)};
        \addplot {1/sqrt(2^2 + x^2)};
        \addplot {1/sqrt(3^2 + x^2)};
\end{groupplot}
\end{tikzpicture}
\end{document}

enter image description here

答案2

只需使用\begin{tabular}{ll}

\documentclass{scrartcl}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}

\begin{document}

\pgfplotsset{
  height=4cm, width=\linewidth*0.5,
  every axis plot post/.append style={mark=none},
  xmin=-1, xmax=1, domain=-1:1, samples=100, minor y tick num=1,
  xtick=\empty
}

\begin{tabular}{ll}
  \begin{tikzpicture}[baseline,trim axis left]
    \begin{axis}[title=Gaussian,
      legend entries={$s=2$, $s=4$,$s=8$}]
      \addplot {exp(- (2*x)^2)};
      \addplot {exp(- (4*x)^2)};
      \addplot {exp(- (8*x)^2)};
    \end{axis}
  \end{tikzpicture}
  &
    \begin{tikzpicture}[baseline,trim axis right]
      \begin{axis}[title=Volume Splines]
        \addplot {abs(x)};
      \end{axis}
    \end{tikzpicture}
  \\
  \begin{tikzpicture}[baseline,trim axis left]
    \begin{axis}[title=Multi Quadrics,
      legend entries={$s=2$, $s=4$,$s=6$},
      xtick={}]
      \addplot {sqrt(2^2 + x^2)};
      \addplot {sqrt(4^2 + x^2)};
      \addplot {sqrt(6^2 + x^2)};
    \end{axis}
  \end{tikzpicture}
  &
    \begin{tikzpicture}[baseline,trim axis right]
      \begin{axis}[title=Inverse Multi Quadrics,
        legend entries={$s=1$, $s=2$,$s=3$},
        xtick={}]
        \addplot {1/sqrt(1^2 + x^2)};
        \addplot {1/sqrt(2^2 + x^2)};
        \addplot {1/sqrt(3^2 + x^2)};
      \end{axis}
    \end{tikzpicture}
\end{tabular}

\end{document}

figure aligned

相关内容