我有奇数个图,5 个,我想使用 groupplot 以及组 x 轴标签将第五个图居中对齐。我有一个 3x2 设置。我搜索了答案,我看到有人使用 stackengine 和单独的轴环境,但是我想保留 groupplot 标题,我发现编码更有条理,尤其是在图数量很多的情况下。如果您有任何建议,请提供意见,否则请帮助我将最后一个图居中。
\documentclass[tikz,border=1.2pt]{standalone}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots,tikz}
\usepackage{fixltx2e}
\usepackage{siunitx}
\usepackage{xcolor}
\usepackage[version=4]{mhchem}
\usepgfplotslibrary{groupplots}
\usetikzlibrary{matrix}
\DeclareSIUnit{\molar}{M}
\pgfplotsset{compat=newest}
\pagestyle{empty}
\begin{document}
\begin{tikzpicture}[scale=0.75]
\begin{groupplot}[
group style={
rows=3,
columns=2,
horizontal sep=50pt,
vertical sep=50pt
},
xlabel={},
ylabel={},
xtick pos=left,
ytick pos=left,
scaled x ticks=real:1e-6,
xtick scale label code/.code={},
]
\nextgroupplot[title=\textbf{(a)}]
\addplot [only marks, mark=o] {x^2};\label{raw}
\addplot [smooth] {x^3}; \label{fit}
\coordinate (top) at (rel axis cs:0,1);
\nextgroupplot[title=\textbf{(b)}]
\addplot [only marks, mark=o] {x^2};
\nextgroupplot[title=\textbf{(c)}]
\addplot [only marks, mark=o] {x^2};
\nextgroupplot[title=\textbf{(d)}]
\addplot [only marks, mark=o] {x^2};
\nextgroupplot[title=\textbf{(c)}]
\addplot [only marks, mark=o] {x^2};
\coordinate (bot) at (rel axis cs:1,0);
\end{groupplot}
\node at ($(group c1r1.west)!0.5!(group c1r2.west)$)[xshift=-1.2cm]{\rotatebox{90}{\Large{$\Delta$y}}};
\node at ($(group c1r3.south)!0.5!(group c1r3.south)$)[yshift=-1cm]{\Large{$x$}}};
\path (top|-current bounding box.north)--
coordinate(legendpos)
(bot|-current bounding box.north);
\matrix[
matrix of nodes,
anchor=south,
draw,
inner sep=0.2em,
draw
]at([yshift=1ex]legendpos)
{
\ref{raw}& data points &[5pt]
\ref{fit}& fitted curve\\};
\end{tikzpicture}
\end{document}
答案1
在 中groupplot
,每个图都命名为group c<number>r<number>
,其中最后一部分分别表示图的列号和行号。使用此功能,您可以使用库calc
来放置最后一个图,例如使用
\nextgroupplot[title=\textbf{(c)},
at = { ($ ( $ (group c1r2.south west) + (0,-100pt)$ )!0.5!(group c2r2.south east) $ ) }]
代码(我删除了最后的\node
文本中的虚假右括号并将其更改\Large{...}
为{\Large...}
):
\documentclass[tikz,border=1.2pt]{standalone}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots,tikz}
\usepackage{fixltx2e}
\usepackage{siunitx}
\usepackage{xcolor}
\usepackage[version=4]{mhchem}
\usepgfplotslibrary{groupplots}
\usetikzlibrary{matrix,calc}
\DeclareSIUnit{\molar}{M}
\pgfplotsset{compat=newest}
\pagestyle{empty}
\begin{document}
\begin{tikzpicture}[scale=0.75]
\begin{groupplot}[
group style={
rows=3,
columns=2,
horizontal sep=50pt,
vertical sep=50pt
},
xlabel={},
ylabel={},
xtick pos=left,
ytick pos=left,
scaled x ticks=real:1e-6,
xtick scale label code/.code={},
]
\nextgroupplot[title=\textbf{(a)}]
\addplot [only marks, mark=o] {x^2};
\nextgroupplot[title=\textbf{(b)}]
\addplot [only marks, mark=o] {x^2};
\nextgroupplot[title=\textbf{(c)}]
\addplot [only marks, mark=o] {x^2};
\nextgroupplot[title=\textbf{(d)}]
\addplot [only marks, mark=o] {x^2};
\nextgroupplot[title=\textbf{(e)},
at = { ($ ( $ (group c1r2.south west) + (0,-100pt)$ )!0.5!(group c2r2.south east) $ ) }]
\addplot [only marks, mark=o] {x^2};
\end{groupplot}
\node[xshift=-1.2cm] at
($(group c1r1.west)!0.5!(group c1r2.west)$)
{\rotatebox{90}{{\Large $\Delta$y}}};
\node[yshift=-1cm]
at (group c1r3.south)
{{\Large$x$}};
\end{tikzpicture}
\end{document}