tikzplotlib
tikzplotlib copied to clipboard
Out-of-order subplots don't work
If subplots are generated in a different order (e.g., 2 before 1), then tikzplotlib incorrectly generates multiple groupplot environments, breaking the placement.
from matplotlib import pyplot as plt
import tikzplotlib
import numpy as np
plt.subplot(2, 1, 2) # Note: subplot 2 is accessed before subplot 1
plt.plot([0, 0, 0])
plt.subplot(2, 1, 1)
plt.plot([3, 4, 5])
print(tikzplotlib.get_tikz_code())
Original Matplotlib PDF:
Resulting TeX:
python3 temp.py
% This file was created by tikzplotlib v0.9.2.
\begin{tikzpicture}
\definecolor{color0}{rgb}{0.12156862745098,0.466666666666667,0.705882352941177}
\begin{groupplot}[group style={group size=1 by 2}]
\nextgroupplot[
tick align=outside,
tick pos=left,
x grid style={white!69.0196078431373!black},
xmin=-0.1, xmax=2.1,
xtick style={color=black},
y grid style={white!69.0196078431373!black},
ymin=-0.055, ymax=0.055,
ytick style={color=black}
]
\addplot [semithick, color0]
table {%
0 0
1 0
2 0
};
\end{groupplot}
\begin{groupplot}[group style={group size=1 by 2}]
\nextgroupplot[
tick align=outside,
tick pos=left,
x grid style={white!69.0196078431373!black},
xmin=-0.1, xmax=2.1,
xtick style={color=black},
y grid style={white!69.0196078431373!black},
ymin=2.9, ymax=5.1,
ytick style={color=black}
]
\addplot [semithick, color0]
table {%
0 3
1 4
2 5
};
\end{groupplot}
\end{tikzpicture}
Expected result: The same, but without \end{groupplot} \begin{groupplot}[...]
in the middle.