tikzplotlib
tikzplotlib copied to clipboard
Labels are not translated in Boxplot
trafficstars
When using a boxplot with custom labels, the latter are not translated into Pgfplot.
Python Code
Here is a MWE in Python / Matplotlib:
import tikzplotlib
from matplotlib import pyplot as plt
plt.figure("test_fig", figsize=[4, 4])
plt.boxplot([[1, 2, 3], [4, 5, 6]], labels=["God", "Nietzsche"])
plt.ylabel("Credibility")
tikzplotlib.save("fig.tex")
plt.show()
Which produced the following figure:

Output TeX Code
I wrapped the output code so that it can compile as standalone:
TeX Code
\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\pgfplotsset{width=8cm, height=7cm, compat=1.18}
\usepackage{tikz}
\begin{document}
% This file was created with tikzplotlib v0.10.1.
\begin{tikzpicture}
\definecolor{darkgray176}{RGB}{176,176,176}
\definecolor{darkorange25512714}{RGB}{255,127,14}
\begin{axis}[
tick align=outside,
tick pos=left,
x grid style={darkgray176},
xmin=0.5, xmax=2.5,
xtick style={color=black},
y grid style={darkgray176},
ylabel={Credibility},
ymin=0.75, ymax=6.25,
ytick style={color=black}
]
\addplot [black]
table {%
0.925 1.5
1.075 1.5
1.075 2.5
0.925 2.5
0.925 1.5
};
\addplot [black]
table {%
1 1.5
1 1
};
\addplot [black]
table {%
1 2.5
1 3
};
\addplot [black]
table {%
0.9625 1
1.0375 1
};
\addplot [black]
table {%
0.9625 3
1.0375 3
};
\addplot [black]
table {%
1.925 4.5
2.075 4.5
2.075 5.5
1.925 5.5
1.925 4.5
};
\addplot [black]
table {%
2 4.5
2 4
};
\addplot [black]
table {%
2 5.5
2 6
};
\addplot [black]
table {%
1.9625 4
2.0375 4
};
\addplot [black]
table {%
1.9625 6
2.0375 6
};
\addplot [darkorange25512714]
table {%
0.925 2
1.075 2
};
\addplot [darkorange25512714]
table {%
1.925 5
2.075 5
};
\end{axis}
\end{tikzpicture}
\end{document}
Which produces the following figure:

As one may notice, the x-axis labels are gone, which is annoying when one wonders in which entity one should put ones beliefs.
Expected TeX Code
The following lines should be present in the axis description:
xtick={1,2},
xticklabels={God,Nietzsche}
Leading to the complete code:
TeX Code
\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\pgfplotsset{width=8cm, height=7cm, compat=1.18}
\usepackage{tikz}
\begin{document}
% This file was created with tikzplotlib v0.10.1.
\begin{tikzpicture}
\definecolor{darkgray176}{RGB}{176,176,176}
\definecolor{darkorange25512714}{RGB}{255,127,14}
\begin{axis}[
tick align=outside,
tick pos=left,
x grid style={darkgray176},
xmin=0.5, xmax=2.5,
xtick style={color=black},
y grid style={darkgray176},
ylabel={Credibility},
ymin=0.75, ymax=6.25,
ytick style={color=black},
xtick={1,2},
xticklabels={God,Nietzsche}
]
\addplot [black]
table {%
0.925 1.5
1.075 1.5
1.075 2.5
0.925 2.5
0.925 1.5
};
\addplot [black]
table {%
1 1.5
1 1
};
\addplot [black]
table {%
1 2.5
1 3
};
\addplot [black]
table {%
0.9625 1
1.0375 1
};
\addplot [black]
table {%
0.9625 3
1.0375 3
};
\addplot [black]
table {%
1.925 4.5
2.075 4.5
2.075 5.5
1.925 5.5
1.925 4.5
};
\addplot [black]
table {%
2 4.5
2 4
};
\addplot [black]
table {%
2 5.5
2 6
};
\addplot [black]
table {%
1.9625 4
2.0375 4
};
\addplot [black]
table {%
1.9625 6
2.0375 6
};
\addplot [darkorange25512714]
table {%
0.925 2
1.075 2
};
\addplot [darkorange25512714]
table {%
1.925 5
2.075 5
};
\end{axis}
\end{tikzpicture}
\end{document}
which produces the following figure:
