Boxplot-Diagramm - Neue Linie für lange xticklabels

Boxplot-Diagramm - Neue Linie für lange xticklabels

Ich möchte, dass zwischen meinen „xticklabels“ eine neue Zeile steht, damit sie zweizeilig sind und nicht so eng. Der doppelte Backslash \\ und \n hat nicht funktioniert.

mein Diagramm

Code:

\documentclass{standalone}
\usepackage{tikz,pgfplots,pgfplotstable}
\pgfplotsset{compat=1.18}
\usepgfplotslibrary{statistics}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
    width=0.9\textwidth,
    boxplot/draw direction=y,
    axis y line=left,
    enlarge y limits,
    ylabel={Impact of latency},
    xlabel={Game and latency},
    ytick={1, 2, 3, 4, 5},
    yticklabels={1, 2, 3, 4, 5},
    ymajorgrids,
    xtick={1, 2, 3, 4},
    xticklabels={Chess 0ms ,  Chess 1000ms, Pong 0ms, Pong 1000ms},
]

\addplot+ [boxplot prepared={lower whisker=1, upper whisker=2}] coordinates {};
\addplot+ [boxplot prepared={lower whisker=2, upper whisker=4}] coordinates {};
\addplot+ [boxplot prepared={lower whisker=1, upper whisker=2}] coordinates {};
\addplot+ [boxplot prepared={lower whisker=4, upper whisker=5}] coordinates {};

\end{axis}
\end{tikzpicture}

\end{document}

Antwort1

Um Linien mit \\in Knoten zu unterbrechen, müssen Sie deren Ausrichtung mit festlegen align. Fügen Sie hinzu

xticklabel style={align=center}

und Sie können verwenden

xticklabels={Chess\\ 0ms,  Chess\\ 1000ms, Pong\\ 0ms, Pong\\ 1000ms},

Vollständiges Beispiel (ich habe es entfernt axis y line=leftund auf der linken Seite des Felds Pfeile hinzugefügt):

\documentclass{standalone}
\usepackage{tikz,pgfplots,pgfplotstable}
\pgfplotsset{compat=1.18}
\usepgfplotslibrary{statistics}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
    width=0.9\textwidth,
    boxplot/draw direction=y,
    enlarge y limits,
    ylabel={Impact of latency},
    xlabel={Game and latency},
    ytick={1, 2, 3, 4, 5},
    ymajorgrids,
    xtick={1, 2, 3, 4},
    xticklabels={Chess\\ 0ms,  Chess\\ 1000ms, Pong\\ 0ms, Pong\\ 1000ms},
    xticklabel style={align=center}
]

\addplot+ [boxplot prepared={lower whisker=1, upper whisker=2}] coordinates {};
\addplot+ [boxplot prepared={lower whisker=2, upper whisker=4}] coordinates {};
\addplot+ [boxplot prepared={lower whisker=1, upper whisker=2}] coordinates {};
\addplot+ [boxplot prepared={lower whisker=4, upper whisker=5}] coordinates {};

\end{axis}
\end{tikzpicture}

\end{document}

Vollständiges Beispiel

verwandte Informationen