在两组的群图中绘制公共轴

在两组的群图中绘制公共轴

我有一个groupplot大小为 1 的组2 by 1,想在两个组上绘制一个公共轴。这是我所拥有的

\begin{tikzpicture}
  \begin{groupplot}[
    group style={
      group name=my plots,
      group size=2 by 1,
      ylabels at=edge left,
      xlabels at=edge bottom,
      horizontal sep=0pt
    },
    yticklabels={,,},
    xticklabels={,,},
    ]

    \nextgroupplot[
    tickpos=left,
    xlabel=$x_2$,
    ylabel=$x_3$,
    xmin=-0.5, xmax=10.5,
    ymin=-0.5, ymax=10.5,
    ]
    \addplot [red, only marks, samples=50, mark size=0.75, domain=0:10] {5+5*rand)};
    \nextgroupplot[
    xtick pos = left,
    ytick pos = right,
    xlabel=$x_2$,
    ylabel=$x_3$,
    xmin=-0.5, xmax=10.5,
    ymin=-0.5, ymax=10.5,
    ]
    \addplot [red, only marks, samples=50, mark size=0.75, domain=0:10] {5+5*rand)};
  \end{groupplot}

  \begin{axis}[
    hide y axis,
    axis x line=top,
    xlabel=$x_1$,
    tick align=inside,    
    xticklabels={,,},
    xmin=0, xmax=1,
    scale=2,
    ]
  \end{axis}
\end{tikzpicture}

不幸的是,附加轴绘制在组图上方。我该如何对齐此轴?

此外,如何向组图轴添加箭头? axis line style=->不起作用。

谢谢你!

答案1

这就是你想要的吗?我设置了最后一个 的anchor和 位置(用) ,因此它的左上角位于 的左上角。对于轴上的箭头,您可能需要添加,这样轴的四边就会被绘制为单独的路径。ataxisgroupplotseparate axis lines

在此处输入图片描述

\documentclass[border = 2mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\usepgfplotslibrary{groupplots}
\begin{document}
\begin{tikzpicture}
  \begin{groupplot}[
    group style={
      group name=my plots,
      group size=2 by 1,
      ylabels at=edge left,
      xlabels at=edge bottom,
      horizontal sep=0pt,
    },
    yticklabels={},
    xticklabels={},
    xlabel=$x_2$,
    separate axis lines, % <-- added
    axis x line=bottom,  % <-- added
    axis line style={-stealth, line cap=rect},
    xmin=-0.5, xmax=10.5,
    ymin=-0.5, ymax=10.5,
    ]

    \nextgroupplot[
      tickpos=left,
      ylabel=$x_3$,
    ]
    \addplot [red, only marks, samples=50, mark size=0.75, domain=0:10] {5+5*rand)};

    \nextgroupplot[
    xtick pos = left,
    ytick pos = right,
    ylabel=$x_3$,
    ]
    \addplot [red, only marks, samples=50, mark size=0.75, domain=0:10] {5+5*rand)};
  \end{groupplot}


  \begin{axis}[
    anchor=north west, % <-- added
    at=(my plots c1r1.north west),  % <-- added
    hide y axis,
    axis x line=top,
    xlabel=$x_1$,
    tick align=inside,    
    xticklabels={},
    xmin=0, xmax=1,
    scale=2,
    ]
  \end{axis}
\end{tikzpicture}
\end{document}

相关内容