Skip to content

Commit

Permalink
Merge pull request #379 from nschloe/compile-check
Browse files Browse the repository at this point in the history
Compile check
  • Loading branch information
nschloe committed Jan 16, 2020
2 parents e0e698d + 485fb76 commit b7cb3a0
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 28 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,21 @@ tikzplotlib.save("test.tex")
\definecolor{color1}{rgb}{0.203921568627451,0.541176470588235,0.741176470588235}
\begin{axis}[
axis background/.style={fill=white!89.80392156862746!black},
axis background/.style={fill=white!89.8039215686275!black},
axis line style={white},
tick align=outside,
tick pos=left,
title={Simple plot $\frac{\alpha}{2}$},
title={Simple plot \(\displaystyle \frac{\alpha}{2}\)},
x grid style={white},
xlabel={time (s)},
xmajorgrids,
xmin=-0.095, xmax=1.995,
xtick style={color=white!33.3333333333333!black},
y grid style={white},
ylabel={Voltage (mV)},
ymajorgrids,
ymin=-1.1, ymax=1.1
ymin=-1.1, ymax=1.1,
ytick style={color=white!33.3333333333333!black}
]
\addplot [line width=1.64pt, color0, mark=*, mark size=3, mark options={solid}]
table {%
Expand Down
15 changes: 10 additions & 5 deletions test/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ def _unidiff_output(expected, actual):
return "".join(diff)


def assert_equality(plot, filename, **extra_get_tikz_code_args):
def assert_equality(
plot, filename, assert_compilation=True, **extra_get_tikz_code_args
):
plot()
code = tikzplotlib.get_tikz_code(
include_disclaimer=False, float_format=".8g", **extra_get_tikz_code_args
Expand All @@ -42,10 +44,13 @@ def assert_equality(plot, filename, **extra_get_tikz_code_args):
reference = f.read()
assert reference == code, _unidiff_output(code, reference)

code = tikzplotlib.get_tikz_code(
include_disclaimer=False, standalone=True, **extra_get_tikz_code_args
)
assert _compile(code) is not None
if assert_compilation:
plot()
code = tikzplotlib.get_tikz_code(
include_disclaimer=False, standalone=True, **extra_get_tikz_code_args
)
plt.close()
assert _compile(code) is not None, code


def _compile(code):
Expand Down
2 changes: 1 addition & 1 deletion test/test_annotate_reference.tex
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
text=black,
rotate=0.0
]{arrowstyle};
\draw (axis cs:0,1) ++(50px,-30px) node[
\draw (axis cs:50,-30) node[
scale=0.5,
anchor=base west,
text=black,
Expand Down
3 changes: 1 addition & 2 deletions test/test_colorbars.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ def plot():


def test():
assert_equality(plot, "test_colorbars_reference.tex")
return
assert_equality(plot, "test_colorbars_reference.tex", assert_compilation=False)


if __name__ == "__main__":
Expand Down
1 change: 0 additions & 1 deletion test/test_legend_line_scatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ def plot():

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


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion test/test_legend_line_scatter_reference.tex
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
ymin=-0.23928571, ymax=4.2392857,
ytick style={color=black}
]
\addplot [only marks, marker=*, draw=color0, fill=color0, colormap/viridis]
\addplot [only marks, mark=*, draw=color0, fill=color0, colormap/viridis]
table{%
x y
0 0
Expand Down
2 changes: 1 addition & 1 deletion test/test_marker_reference.tex
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
ymin=-1.1, ymax=1.1,
ytick style={color=black}
]
\addplot [only marks, marker=+, draw=black, fill=black, colormap/viridis]
\addplot [only marks, mark=+, draw=black, fill=black, colormap/viridis]
table{%
x y
0 0
Expand Down
2 changes: 1 addition & 1 deletion test/test_scatter_reference.tex
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
ymin=0.16291984, ymax=112.82609,
ytick style={color=black}
]
\addplot [only marks, marker=*, draw=color0, fill=color0, colormap/viridis]
\addplot [only marks, mark=*, draw=color0, fill=color0, colormap/viridis]
table{%
x y
0 10.447038
Expand Down
2 changes: 1 addition & 1 deletion tikzplotlib/_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def draw_pathcollection(data, obj):
data, pgfplots_marker, marker_options = _mpl_marker2pgfp_marker(
data, marker0, fc
)
draw_options += [f"marker={pgfplots_marker}"] + marker_options
draw_options += [f"mark={pgfplots_marker}"] + marker_options

# `only mark` plots don't need linewidth
data, extra_draw_options = get_draw_options(data, obj, ec, fc, ls, None)
Expand Down
15 changes: 7 additions & 8 deletions tikzplotlib/_save.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,20 +218,19 @@ def get_tikz_code(
code += "\\end{tikzpicture}\n"

if standalone:
# When using pdflatex, this is necessary:
# \\DeclareUnicodeCharacter{{2212}}{{−}}
code = """\\documentclass{{standalone}}
# When using pdflatex, \\DeclareUnicodeCharacter is necessary.
code = f"""\\documentclass{{standalone}}
\\usepackage[utf8]{{inputenc}}
\\usepackage{{pgfplots}}
\\DeclareUnicodeCharacter{{2212}}{{−}}
\\usepgfplotslibrary{{groupplots}}
\\usepgfplotslibrary{{dateplot}}
\\usetikzlibrary{{patterns}}
\\usetikzlibrary{{shapes.arrows}}
\\pgfplotsset{{compat=newest}}
\\begin{{document}}
{}
\\end{{document}}\n""".format(
code
)

{code}
\\end{{document}}\n"""
return code


Expand Down
8 changes: 4 additions & 4 deletions tikzplotlib/_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,10 @@ def _annotation(obj, data, content):
x, y = ann_xytext
unit = "pt"
text_pos = f"{xy_pos} ++({x:{ff}}{unit},{y:{ff}}{unit})"
elif ann_textcoords == "offset pixels":
x, y = ann_xytext
unit = "px"
text_pos = f"{xy_pos} ++({x:{ff}}{unit},{y:{ff}}{unit})"
# elif ann_textcoords == "offset pixels":
# x, y = ann_xytext
# unit = "px"
# text_pos = f"{xy_pos} ++({x:{ff}}{unit},{y:{ff}}{unit})"
else:
try:
text_pos = _parse_annotation_coords(ff, ann_xycoords, ann_xytext)
Expand Down

0 comments on commit b7cb3a0

Please sign in to comment.