标签在组图中移位

标签在组图中移位

我正在尝试使用groupplot环境绘制 6 个图表。据我所知,y 标签位于轴值的左侧,但由于不同图形上的值不同,因此导致标签不对齐,并且它也可以放置在左列的图形上。这是我得到的示例: 在此处输入图片描述 来自此代码:

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usepgfplotslibrary{groupplots}

\begin{document}

\begin{tikzpicture}

\begin{groupplot}[
        group style={group size=2 by 3},
        width=6cm,
        height=4cm,
    ]
\nextgroupplot[
xlabel={t},
ylabel={N1},
]
\addplot [thick, red, dashed]
table {%
4 2.52402186393738
21 0.0392908006906509
};
\nextgroupplot[
xlabel={t},
ylabel={N2},
]
\addplot [thick, red, dashed]
table {%
4 0.00180898304097354
21 4.06462144851685
};
\nextgroupplot[
xlabel={t},
ylabel={N3},
]
\addplot [thick, red, dashed]
table {%
4 0.0086209699511528
21 0.431585133075714
};
\nextgroupplot[
xlabel={t},
ylabel={N4},
]
\addplot [thick, red, dashed]
table {%
4 0.034182284027338
21 2.88350582122803
};
\nextgroupplot[
xlabel={t},
ylabel={N5},
]
\addplot [thick, red, dashed]
table {%
4 0.0330703742802143
21 1.12964105606079
};
\nextgroupplot[
xlabel={t},
ylabel={N6},
]
\addplot [thick, red, dashed]
table {%
4 0.641332507133484
21 1.23090080350607e-08
};
\end{groupplot}

\end{tikzpicture}

\end{document}

我怎样才能将这些标签设置为对齐,并且不与其他图形叠加?

答案1

像这样:

在此处输入图片描述

为了对样式选项进行分组,我添加horizontal sep=4em并定义yticklabel宽度:

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\usepgfplotslibrary{groupplots}

\begin{document}
    \begin{tikzpicture}
\begin{groupplot}[
        group style={group size=2 by 3,
                     horizontal sep=4em},     % <--- added
        width=6cm,  height=4cm,
    yticklabel style = {font=\small},  % <--- added
    yticklabel style = {text width=1.1em, align=right, font=\small},  % <--- added
                ]
\nextgroupplot[
xlabel={t},
ylabel={N1},
]
\addplot [thick, red, dashed]
table {%
4 2.52402186393738
21 0.0392908006906509
};
\nextgroupplot[
xlabel={t},
ylabel={N2},
]
\addplot [thick, red, dashed]
table {%
4 0.00180898304097354
21 4.06462144851685
};
\nextgroupplot[
xlabel={t},
ylabel={N3},
]
\addplot [thick, red, dashed]
table {%
4 0.0086209699511528
21 0.431585133075714
};
\nextgroupplot[
xlabel={t},
ylabel={N4},
]
\addplot [thick, red, dashed]
table {%
4 0.034182284027338
21 2.88350582122803
};
\nextgroupplot[
xlabel={t},
ylabel={N5},
]
\addplot [thick, red, dashed]
table {%
4 0.0330703742802143
21 1.12964105606079
};
\nextgroupplot[
xlabel={t},
ylabel={N6},
]
\addplot [thick, red, dashed]
table {%
4 0.641332507133484
21 1.23090080350607e-08
};
\end{groupplot}
    \end{tikzpicture}
\end{document}

相关内容