Skip to content

Commit ec66cbb

Browse files
committed
escape chars in title, too
Fixes #332.
1 parent 84a22fb commit ec66cbb

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

test/test_escape_chars.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# https://github.com/nschloe/tikzplotlib/issues/332
2+
import matplotlib.pyplot as plt
3+
4+
from helpers import assert_equality
5+
6+
7+
def plot():
8+
fig = plt.figure()
9+
plt.plot(0, 0, "kx")
10+
plt.title("Foo & Bar Dogs_N_Cats")
11+
plt.xlabel("Foo & Bar Dogs_N_Cats")
12+
plt.ylabel("Foo & Bar Dogs_N_Cats")
13+
return fig
14+
15+
16+
def test():
17+
assert_equality(plot, "test_escape_chars_reference.tex")
18+
return

test/test_escape_chars_reference.tex

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
\begin{tikzpicture}
2+
3+
\begin{axis}[
4+
tick align=outside,
5+
tick pos=left,
6+
title={Foo & Bar Dogs\_N\_Cats},
7+
x grid style={white!69.01960784313725!black},
8+
xlabel={Foo & Bar Dogs\_N\_Cats},
9+
xmin=-0.055, xmax=0.055,
10+
xtick style={color=black},
11+
y grid style={white!69.01960784313725!black},
12+
ylabel={Foo & Bar Dogs\_N\_Cats},
13+
ymin=-0.055, ymax=0.055,
14+
ytick style={color=black}
15+
]
16+
\addplot [semithick, black, mark=x, mark size=3, mark options={solid}, only marks]
17+
table {%
18+
0 0
19+
};
20+
\end{axis}
21+
22+
\end{tikzpicture}

tikzplotlib/axes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ def __init__(self, data, obj): # noqa: C901
3636
title = obj.get_title()
3737
data["current axis title"] = title
3838
if title:
39+
title = mpl_backend_pgf.common_texification(title)
3940
self.axis_options.append(u"title={{{}}}".format(title))
4041

4142
# get axes titles

0 commit comments

Comments
 (0)