0

I currently used tikzplotlib from Python to generate the following plot in LaTeX. However, my current subplots are overlapping in LaTeX while they were not overlapping in Python (I used fig.tight_layout() which I think was not exported in tikzplotlib). I was wondering if you guys know how to adjust the following code so that my title does not overlap with the x-axes from the graph above and the y-axes of the right plots overlaps with the plot of the left plots. Finally, I do want to keep the plot inbetween the width and heigth of the page.

\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}
4
  • Welcome to TeX.SX! Please make your code compilable (if possible), or at least complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem. Aug 2 at 20:09
  • 1
    There is something terrible wrong with your code. What looks like a bar graph is just manual drawing of rectangles and labels. I do not this the code can be saved in the current state. Aug 2 at 20:14
  • You can use group/horizontal sep=2cm, group/vertical sep=2cm (as option to groupplot) to increase the distance between the subplots. But you will probably need to adjust their size as well. Aug 2 at 20:16
  • This seems to indeed work for getting rid of the space inbetween, how would I adjust their size in this case. Sorry, I merely generated this with a python library.
    – Paul
    Aug 2 at 20:19

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.