pgfplot 两行刻度标签

pgfplot 两行刻度标签

在我的 MWE 中,我希望刻度标签“中上”出现在两行上,即上位于第一行,中位于下一行。

\documentclass[a4paper, 12pt]{article}
\usepackage[sfdefault]{atkinson}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\usepgfplotslibrary{statistics}

\begin{document}
\begin{figure}
\begin{tikzpicture}
\begin{axis}[
every y tick label/.append style={font=\scriptsize},
every x tick label/.append style={font=\scriptsize},
xmode=log,
ytick={1,2,3},
yticklabels={High, Upper \\ middle, Low}, <-Make upper middle appear across two lines
%boxplot/variable width,
]
\addplot+ [
boxplot prepared={%High
lower whisker=2.3, lower quartile=6.975,
median= 14.05,
upper quartile=54.6, upper whisker=4000},
black, solid] coordinates {};

\addplot+ [
boxplot prepared={%Upper-middle
lower whisker=2.4, lower quartile=6.8,
median=104,
upper quartile=395.5, upper whisker= 800.0},
black, solid] coordinates {};

\addplot+ [
boxplot prepared={%Low
lower whisker=80, lower quartile=88,
median=96,
upper quartile=104, upper whisker=112},
black, solid] coordinates {};
\end{axis}
\end{tikzpicture}
\end{figure}

\end{document}

另外,如何使轴编号遵循我使用的字体?

答案1

\documentclass[a4paper, 12pt]{article}
\usepackage[sfdefault]{atkinson}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.17}
\usepgfplotslibrary{statistics}

\begin{document}
    \begin{figure}
        \begin{tikzpicture}[scale=1.5]
            \begin{axis}[
                every y tick label/.append style={font=\scriptsize},
                every x tick label/.append style={font=\scriptsize},
                xmode=log,
                ytick={1,2,3},
                y tick label style={align=right, text width=1.5cm}, % <<<--- added line
                yticklabels={High, Upper middle, Low},
                ]
                \addplot+ [
                boxplot prepared={%High
                    lower whisker=2.3, lower quartile=6.975,
                    median= 14.05,
                    upper quartile=54.6, upper whisker=4000},
                black, solid] coordinates {};
                
                \addplot+ [
                boxplot prepared={%Upper-middle
                    lower whisker=2.4, lower quartile=6.8,
                    median=104,
                    upper quartile=395.5, upper whisker= 800.0},
                black, solid] coordinates {};
                
                \addplot+ [
                boxplot prepared={%Low
                    lower whisker=80, lower quartile=88,
                    median=96,
                    upper quartile=104, upper whisker=112},
                black, solid] coordinates {};
            \end{axis}
        \end{tikzpicture}
    \end{figure}
    
\end{document}

在此处输入图片描述

相关内容