Pgfplots의 그룹 플롯, 자동 범례 및 축 이름 배치

Pgfplots의 그룹 플롯, 자동 범례 및 축 이름 배치

그래서 저는 다음 질문에 대한 답변을 준비하고 있습니다.이 질문그리고 그것을 그룹 플롯에 적용하는 작업을 했습니다. 즉, 자동으로 범례를 바깥쪽 여백에 배치하고, 축 눈금 및 레이블을 안쪽에 배치했습니다. 이후 mwe와 관련하여 두 가지 문제에 직면하게 되었습니다.

  • 측면에 따라 축 라벨을 교묘하게 켜고 끄는 방법은 무엇입니까? 가능한 방법은 \ifoddpage를 또 다른 용도로 사용하는 것이지만 제 생각에는 그다지 아름답지는 않습니다. 설명서에서 뭔가를 잊어버렸을 수도 있습니다.
  • trim axis group left/rightJake가 제안한 범례 배치와 함께 사용하는 방법이 질문? 축을 트리밍할 때 범례가 정확히 예상된 결과가 아닌 이전 위치에 배치됩니다...

주요 파일은 다음과 같습니다.

\documentclass{article}
\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}
\usepackage{float}
\usepackage{ifoddpage}


\begin{document}

\begin{figure}[H]
  \input{groupplot}
  \caption{first figure}
\end{figure}

\newpage

\begin{figure}[H]
  \input{groupplot}
  \caption{first figure}
\end{figure}

\end{document}

그리고 그림은 다음과 같습니다 groupplot.tex.

  \checkoddpage
  \ifoddpage
  \def\yticksside{ edge right}
  \else
  \def\yticksside{ edge left}
  \fi

  \centering
  \begin{tikzpicture}%[trim axis group left,trim axis group right]
    \begin{groupplot}[
        group style = {
          group size = 2 by 1,
          horizontal sep=0mm,
    yticklabels at=\yticksside,
        },
        width=0.5\columnwidth,
        ylabel={$y$label},
      ]

      \nextgroupplot[
        xlabel={$x$},
        legend to name=grouplegend,
    ylabel near ticks,
      ]
      \addplot coordinates { (0,0) (1,1) };
      \addlegendentry{Legend entry}

      \nextgroupplot[
        xlabel={$x$},
    ylabel near ticks,
      ]
      \addplot coordinates { (0,0) (1,1) };
    \end{groupplot}

  \checkoddpage
  \ifoddpage
  \def\legendpos{group c1r1.south west}
  \def\legendanchor{north east}
  \else
  \def\legendpos{group c2r1.south east}
  \def\legendanchor{north west}
  \fi

  \node at (\legendpos) [anchor=\legendanchor]  {\ref{grouplegend}};
  \end{tikzpicture}

관련 정보