Gruppendiagramme von Pgfplots, automatische Platzierung von Legenden und Achsennamen

Gruppendiagramme von Pgfplots, automatische Platzierung von Legenden und Achsennamen

Ich habe an einer Antwort gearbeitet aufdiese Frageund daran gearbeitet, es an Gruppendiagramme anzupassen, d. h. die Legende automatisch am äußeren Rand und die Achsenmarkierungen und Beschriftungen an der Innenseite zu platzieren. Danach habe ich mit dem MWE zwei Probleme:

  • Wie kann man die Achsenbeschriftung je nach Seite geschickt ein-/ausschalten? Eine Möglichkeit ist die Verwendung von \ifoddpage, aber ich finde, das ist nicht sehr schön. Vielleicht habe ich etwas aus dem Handbuch vergessen.
  • Verwendung trim axis group left/rightzusammen mit der von Jake in vorgeschlagenen Legendenplatzierungdiese Frage? Beim Trimmen der Achsen wird die Legende an den vorherigen Positionen platziert, was nicht genau den erwarteten Ergebnissen entspricht ...

Hier ist die Hauptdatei:

\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}

Und hier ist die groupplot.texAbbildung:

  \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}

verwandte Informationen