Skip to content

Commit b7cb3a0

Browse files
authored
Merge pull request #379 from nschloe/compile-check
Compile check
2 parents e0e698d + 485fb76 commit b7cb3a0

11 files changed

+32
-28
lines changed

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,19 +59,21 @@ tikzplotlib.save("test.tex")
5959
\definecolor{color1}{rgb}{0.203921568627451,0.541176470588235,0.741176470588235}
6060
6161
\begin{axis}[
62-
axis background/.style={fill=white!89.80392156862746!black},
62+
axis background/.style={fill=white!89.8039215686275!black},
6363
axis line style={white},
6464
tick align=outside,
6565
tick pos=left,
66-
title={Simple plot $\frac{\alpha}{2}$},
66+
title={Simple plot \(\displaystyle \frac{\alpha}{2}\)},
6767
x grid style={white},
6868
xlabel={time (s)},
6969
xmajorgrids,
7070
xmin=-0.095, xmax=1.995,
71+
xtick style={color=white!33.3333333333333!black},
7172
y grid style={white},
7273
ylabel={Voltage (mV)},
7374
ymajorgrids,
74-
ymin=-1.1, ymax=1.1
75+
ymin=-1.1, ymax=1.1,
76+
ytick style={color=white!33.3333333333333!black}
7577
]
7678
\addplot [line width=1.64pt, color0, mark=*, mark size=3, mark options={solid}]
7779
table {%

test/helpers.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ def _unidiff_output(expected, actual):
3030
return "".join(diff)
3131

3232

33-
def assert_equality(plot, filename, **extra_get_tikz_code_args):
33+
def assert_equality(
34+
plot, filename, assert_compilation=True, **extra_get_tikz_code_args
35+
):
3436
plot()
3537
code = tikzplotlib.get_tikz_code(
3638
include_disclaimer=False, float_format=".8g", **extra_get_tikz_code_args
@@ -42,10 +44,13 @@ def assert_equality(plot, filename, **extra_get_tikz_code_args):
4244
reference = f.read()
4345
assert reference == code, _unidiff_output(code, reference)
4446

45-
code = tikzplotlib.get_tikz_code(
46-
include_disclaimer=False, standalone=True, **extra_get_tikz_code_args
47-
)
48-
assert _compile(code) is not None
47+
if assert_compilation:
48+
plot()
49+
code = tikzplotlib.get_tikz_code(
50+
include_disclaimer=False, standalone=True, **extra_get_tikz_code_args
51+
)
52+
plt.close()
53+
assert _compile(code) is not None, code
4954

5055

5156
def _compile(code):

test/test_annotate_reference.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
text=black,
5353
rotate=0.0
5454
]{arrowstyle};
55-
\draw (axis cs:0,1) ++(50px,-30px) node[
55+
\draw (axis cs:50,-30) node[
5656
scale=0.5,
5757
anchor=base west,
5858
text=black,

test/test_colorbars.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ def plot():
7575

7676

7777
def test():
78-
assert_equality(plot, "test_colorbars_reference.tex")
79-
return
78+
assert_equality(plot, "test_colorbars_reference.tex", assert_compilation=False)
8079

8180

8281
if __name__ == "__main__":

test/test_legend_line_scatter.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ def plot():
1717

1818
def test():
1919
assert_equality(plot, __file__[:-3] + "_reference.tex")
20-
return
2120

2221

2322
if __name__ == "__main__":

test/test_legend_line_scatter_reference.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
ymin=-0.23928571, ymax=4.2392857,
1515
ytick style={color=black}
1616
]
17-
\addplot [only marks, marker=*, draw=color0, fill=color0, colormap/viridis]
17+
\addplot [only marks, mark=*, draw=color0, fill=color0, colormap/viridis]
1818
table{%
1919
x y
2020
0 0

test/test_marker_reference.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
ymin=-1.1, ymax=1.1,
1616
ytick style={color=black}
1717
]
18-
\addplot [only marks, marker=+, draw=black, fill=black, colormap/viridis]
18+
\addplot [only marks, mark=+, draw=black, fill=black, colormap/viridis]
1919
table{%
2020
x y
2121
0 0

test/test_scatter_reference.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
ymin=0.16291984, ymax=112.82609,
1717
ytick style={color=black}
1818
]
19-
\addplot [only marks, marker=*, draw=color0, fill=color0, colormap/viridis]
19+
\addplot [only marks, mark=*, draw=color0, fill=color0, colormap/viridis]
2020
table{%
2121
x y
2222
0 10.447038

tikzplotlib/_path.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ def draw_pathcollection(data, obj):
176176
data, pgfplots_marker, marker_options = _mpl_marker2pgfp_marker(
177177
data, marker0, fc
178178
)
179-
draw_options += [f"marker={pgfplots_marker}"] + marker_options
179+
draw_options += [f"mark={pgfplots_marker}"] + marker_options
180180

181181
# `only mark` plots don't need linewidth
182182
data, extra_draw_options = get_draw_options(data, obj, ec, fc, ls, None)

tikzplotlib/_save.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -218,20 +218,19 @@ def get_tikz_code(
218218
code += "\\end{tikzpicture}\n"
219219

220220
if standalone:
221-
# When using pdflatex, this is necessary:
222-
# \\DeclareUnicodeCharacter{{2212}}{{−}}
223-
code = """\\documentclass{{standalone}}
221+
# When using pdflatex, \\DeclareUnicodeCharacter is necessary.
222+
code = f"""\\documentclass{{standalone}}
224223
\\usepackage[utf8]{{inputenc}}
225224
\\usepackage{{pgfplots}}
225+
\\DeclareUnicodeCharacter{{2212}}{{−}}
226226
\\usepgfplotslibrary{{groupplots}}
227227
\\usepgfplotslibrary{{dateplot}}
228+
\\usetikzlibrary{{patterns}}
229+
\\usetikzlibrary{{shapes.arrows}}
228230
\\pgfplotsset{{compat=newest}}
229231
\\begin{{document}}
230-
{}
231-
\\end{{document}}\n""".format(
232-
code
233-
)
234-
232+
{code}
233+
\\end{{document}}\n"""
235234
return code
236235

237236

tikzplotlib/_text.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,10 @@ def _annotation(obj, data, content):
213213
x, y = ann_xytext
214214
unit = "pt"
215215
text_pos = f"{xy_pos} ++({x:{ff}}{unit},{y:{ff}}{unit})"
216-
elif ann_textcoords == "offset pixels":
217-
x, y = ann_xytext
218-
unit = "px"
219-
text_pos = f"{xy_pos} ++({x:{ff}}{unit},{y:{ff}}{unit})"
216+
# elif ann_textcoords == "offset pixels":
217+
# x, y = ann_xytext
218+
# unit = "px"
219+
# text_pos = f"{xy_pos} ++({x:{ff}}{unit},{y:{ff}}{unit})"
220220
else:
221221
try:
222222
text_pos = _parse_annotation_coords(ff, ann_xycoords, ann_xytext)

0 commit comments

Comments
 (0)