Pgfplot 重叠图

Pgfplot 重叠图

我目前使用 Python 中的 tikzplotlib 在 LaTeX 中生成以下图。但是,我当前的子图在 LaTeX 中重叠,而在 Python 中不重叠(我使用了 fig.tight_layout(),但我认为它未在 tikzplotlib 中导出)。我想知道你们是否知道如何调整以下代码,以便我的标题不与上图中的 x 轴重叠,并且右侧图的 y 轴与左侧图的图重叠。最后,我确实希望将图保持在页面的宽度和高度之间。

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}

\begin{document}
\begin{tikzpicture}

\definecolor{darkgray176}{RGB}{176,176,176}
\definecolor{steelblue31119180}{RGB}{31,119,180}

\begin{groupplot}[group style={group size=2 by 3}]
\nextgroupplot[
tick align=outside,
tick pos=left,
title={OLS},
x grid style={darkgray176},
xmin=0, xmax=0.525,
xtick style={color=black},
y dir=reverse,
y grid style={darkgray176},
ymin=-0.69, ymax=5.69,
ytick style={color=black},
ytick={0,1,2,3,4,5},
yticklabels={check,mom1m,indmom,2,3,4}
]
\draw[draw=none,fill=steelblue31119180] (axis cs:0,-0.4) rectangle (axis cs:0.33,0.4);
\draw[draw=none,fill=steelblue31119180] (axis cs:0,0.6) rectangle (axis cs:0.5,1.4);
\draw[draw=none,fill=steelblue31119180] (axis cs:0,1.6) rectangle (axis cs:0.17,2.4);
\draw[draw=none,fill=steelblue31119180] (axis cs:0,2.6) rectangle (axis cs:0.12,3.4);
\draw[draw=none,fill=steelblue31119180] (axis cs:0,3.6) rectangle (axis cs:0.08,4.4);
\draw[draw=none,fill=steelblue31119180] (axis cs:0,4.6) rectangle (axis cs:0.1,5.4);

\nextgroupplot[
tick align=outside,
tick pos=left,
title={ENet + H},
x grid style={darkgray176},
xmin=0, xmax=0.525,
xtick style={color=black},
y dir=reverse,
y grid style={darkgray176},
ymin=-0.69, ymax=5.69,
ytick style={color=black},
ytick={0,1,2,3,4,5},
yticklabels={check,mom1m,indmom,2,3,4}
]
\draw[draw=none,fill=steelblue31119180] (axis cs:0,-0.4) rectangle (axis cs:0.33,0.4);
\draw[draw=none,fill=steelblue31119180] (axis cs:0,0.6) rectangle (axis cs:0.5,1.4);
\draw[draw=none,fill=steelblue31119180] (axis cs:0,1.6) rectangle (axis cs:0.17,2.4);
\draw[draw=none,fill=steelblue31119180] (axis cs:0,2.6) rectangle (axis cs:0.12,3.4);
\draw[draw=none,fill=steelblue31119180] (axis cs:0,3.6) rectangle (axis cs:0.08,4.4);
\draw[draw=none,fill=steelblue31119180] (axis cs:0,4.6) rectangle (axis cs:0.1,5.4);

\nextgroupplot[
tick align=outside,
tick pos=left,
title={PCR},
x grid style={darkgray176},
xmin=0, xmax=0.525,
xtick style={color=black},
y dir=reverse,
y grid style={darkgray176},
ymin=-0.69, ymax=5.69,
ytick style={color=black},
ytick={0,1,2,3,4,5},
yticklabels={check,mom1m,indmom,2,3,4}
]
\draw[draw=none,fill=steelblue31119180] (axis cs:0,-0.4) rectangle (axis cs:0.33,0.4);
\draw[draw=none,fill=steelblue31119180] (axis cs:0,0.6) rectangle (axis cs:0.5,1.4);
\draw[draw=none,fill=steelblue31119180] (axis cs:0,1.6) rectangle (axis cs:0.17,2.4);
\draw[draw=none,fill=steelblue31119180] (axis cs:0,2.6) rectangle (axis cs:0.12,3.4);
\draw[draw=none,fill=steelblue31119180] (axis cs:0,3.6) rectangle (axis cs:0.08,4.4);
\draw[draw=none,fill=steelblue31119180] (axis cs:0,4.6) rectangle (axis cs:0.1,5.4);

\nextgroupplot[
tick align=outside,
tick pos=left,
title={PLS},
x grid style={darkgray176},
xmin=0, xmax=0.525,
xtick style={color=black},
y dir=reverse,
y grid style={darkgray176},
ymin=-0.69, ymax=5.69,
ytick style={color=black},
ytick={0,1,2,3,4,5},
yticklabels={check,mom1m,indmom,2,3,4}
]
\draw[draw=none,fill=steelblue31119180] (axis cs:0,-0.4) rectangle (axis cs:0.33,0.4);
\draw[draw=none,fill=steelblue31119180] (axis cs:0,0.6) rectangle (axis cs:0.5,1.4);
\draw[draw=none,fill=steelblue31119180] (axis cs:0,1.6) rectangle (axis cs:0.17,2.4);
\draw[draw=none,fill=steelblue31119180] (axis cs:0,2.6) rectangle (axis cs:0.12,3.4);
\draw[draw=none,fill=steelblue31119180] (axis cs:0,3.6) rectangle (axis cs:0.08,4.4);
\draw[draw=none,fill=steelblue31119180] (axis cs:0,4.6) rectangle (axis cs:0.1,5.4);

\nextgroupplot[
tick align=outside,
tick pos=left,
title={RF},
x grid style={darkgray176},
xmin=0, xmax=0.525,
xtick style={color=black},
y dir=reverse,
y grid style={darkgray176},
ymin=-0.69, ymax=5.69,
ytick style={color=black},
ytick={0,1,2,3,4,5},
yticklabels={check,mom1m,indmom,2,3,4}
]
\draw[draw=none,fill=steelblue31119180] (axis cs:0,-0.4) rectangle (axis cs:0.33,0.4);
\draw[draw=none,fill=steelblue31119180] (axis cs:0,0.6) rectangle (axis cs:0.5,1.4);
\draw[draw=none,fill=steelblue31119180] (axis cs:0,1.6) rectangle (axis cs:0.17,2.4);
\draw[draw=none,fill=steelblue31119180] (axis cs:0,2.6) rectangle (axis cs:0.12,3.4);
\draw[draw=none,fill=steelblue31119180] (axis cs:0,3.6) rectangle (axis cs:0.08,4.4);
\draw[draw=none,fill=steelblue31119180] (axis cs:0,4.6) rectangle (axis cs:0.1,5.4);

\nextgroupplot[
tick align=outside,
tick pos=left,
title={GBRT},
x grid style={darkgray176},
xmin=0, xmax=0.525,
xtick style={color=black},
y dir=reverse,
y grid style={darkgray176},
ymin=-0.69, ymax=5.69,
ytick style={color=black},
ytick={0,1,2,3,4,5},
yticklabels={check,mom1m,indmom,2,3,4}
]
\draw[draw=none,fill=steelblue31119180] (axis cs:0,-0.4) rectangle (axis cs:0.33,0.4);
\draw[draw=none,fill=steelblue31119180] (axis cs:0,0.6) rectangle (axis cs:0.5,1.4);
\draw[draw=none,fill=steelblue31119180] (axis cs:0,1.6) rectangle (axis cs:0.17,2.4);
\draw[draw=none,fill=steelblue31119180] (axis cs:0,2.6) rectangle (axis cs:0.12,3.4);
\draw[draw=none,fill=steelblue31119180] (axis cs:0,3.6) rectangle (axis cs:0.08,4.4);
\draw[draw=none,fill=steelblue31119180] (axis cs:0,4.6) rectangle (axis cs:0.1,5.4);
\end{groupplot}

\end{tikzpicture}

\end{document}

相关内容