Skip to content

Commit

Permalink
Merge pull request #492 from nschloe/test-warnings
Browse files Browse the repository at this point in the history
fix test warnings
  • Loading branch information
nschloe committed Jun 21, 2021
2 parents 51f8e29 + a324501 commit d2af95f
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 81 deletions.
9 changes: 4 additions & 5 deletions src/tikzplotlib/_cleanfigure.py
Original file line number Diff line number Diff line change
Expand Up @@ -1280,18 +1280,17 @@ def _cross_lines(X1, X2, X3, X4):
:param X4: X4
:type X4: np.ndarray
"""
n = X2.shape[0]
Lambda = np.zeros((n, 2))
detA = -(X2[:, 0] - X1[:, 0]) * (X4[1] - X3[1]) + (X2[:, 1] - X1[:, 1]) * (
X4[0] - X3[0]
)

id_detA = detA != 0

n = X2.shape[0]
Lambda = np.zeros((n, 2))
if id_detA.any():
rhs = -X1.reshape((-1, 2)) + X3.reshape(
(-1, 2)
) # NOTE: watch out for broadcasting
# NOTE: watch out for broadcasting
rhs = -X1.reshape((-1, 2)) + X3.reshape((-1, 2))
Rotate = np.array([[0, -1], [1, 0]])
Lambda[id_detA, 0] = (rhs[id_detA, :] @ Rotate @ (X4 - X3).T) / detA[id_detA]
Lambda[id_detA, 1] = (
Expand Down
17 changes: 9 additions & 8 deletions src/tikzplotlib/_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def draw_path(data, path, draw_options=None, simplify=None):
ff = data["float format"]
xformat = "" if x_is_date else ff
prev = None
is_area = None
for vert, code in path.iter_segments(simplify=simplify):
# nschloe, Oct 2, 2015:
# The transform call yields warnings and it is unclear why. Perhaps
Expand Down Expand Up @@ -199,12 +200,12 @@ def draw_pathcollection(data, obj):
"visualization depends on={value \\thisrow{draw} \\as \\drawcolor}",
"visualization depends on={value \\thisrow{fill} \\as \\fillcolor}",
"scatter/@pre marker code/.code={%\n"
" \\expanded{%\n"
" \\noexpand\\definecolor{thispointdrawcolor}{RGB}{\\drawcolor}%\n"
" \\noexpand\\definecolor{thispointfillcolor}{RGB}{\\fillcolor}%\n"
" }%\n"
" \\scope[draw=thispointdrawcolor, fill=thispointfillcolor]%\n"
"}",
+ " \\expanded{%\n"
+ " \\noexpand\\definecolor{thispointdrawcolor}{RGB}{\\drawcolor}%\n"
+ " \\noexpand\\definecolor{thispointfillcolor}{RGB}{\\fillcolor}%\n"
+ " }%\n"
+ " \\scope[draw=thispointdrawcolor, fill=thispointfillcolor]%\n"
+ "}",
"scatter/@post marker code/.code={%\n" " \\endscope\n" "}",
]
)
Expand Down Expand Up @@ -274,9 +275,9 @@ def draw_pathcollection(data, obj):
draw_options.extend(
[
"visualization depends on="
"{\\thisrow{sizedata} \\as\\perpointmarksize}",
+ "{\\thisrow{sizedata} \\as\\perpointmarksize}",
"scatter/@pre marker code/.append style="
"{/tikz/mark size=\\perpointmarksize}",
+ "{/tikz/mark size=\\perpointmarksize}",
# "scatter/@post marker code/.style={}"
]
)
Expand Down
134 changes: 67 additions & 67 deletions tests/test_cleanfigure.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ def test_plot(self):
# the baseline (raw) should have 20 points
# the clean version (clean) should have 2 points
# the difference in line numbers should therefore be 2
numLinesRaw = raw.count("\n")
numLinesClean = clean.count("\n")
assert numLinesRaw - numLinesClean == 18
num_lines_raw = raw.count("\n")
num_lines_clean = clean.count("\n")
assert num_lines_raw - num_lines_clean == 18
plt.close("all")

def test_step(self):
Expand All @@ -50,7 +50,7 @@ def test_scatter(self):
x = np.linspace(1, 100, 20)
y = np.linspace(1, 100, 20)
with plt.rc_context(rc=RC_PARAMS):
fig, ax = plt.subplots(1, 1, figsize=(5, 5))
_, ax = plt.subplots(1, 1, figsize=(5, 5))
ax.scatter(x, y)
ax.set_ylim([20, 80])
ax.set_xlim([20, 80])
Expand All @@ -63,9 +63,9 @@ def test_scatter(self):
# the baseline (raw) should have 20 points
# the clean version (clean) should have 2 points
# the difference in line numbers should therefore be 2
numLinesRaw = raw.count("\n")
numLinesClean = clean.count("\n")
assert numLinesRaw - numLinesClean == 6
num_lines_raw = raw.count("\n")
num_lines_clean = clean.count("\n")
assert num_lines_raw - num_lines_clean == 6
plt.close("all")

def test_bar(self):
Expand Down Expand Up @@ -113,9 +113,9 @@ def test_plot3d(self):
clean = get_tikz_code()

# Use number of lines to test if it worked.
numLinesRaw = raw.count("\n")
numLinesClean = clean.count("\n")
assert numLinesRaw - numLinesClean == 13
num_lines_raw = raw.count("\n")
num_lines_clean = clean.count("\n")
assert num_lines_raw - num_lines_clean == 13
plt.close("all")

def test_scatter3d(self):
Expand All @@ -139,10 +139,10 @@ def test_scatter3d(self):
clean = get_tikz_code()

# Use number of lines to test if it worked.
numLinesRaw = raw.count("\n")
numLinesClean = clean.count("\n")
num_lines_raw = raw.count("\n")
num_lines_clean = clean.count("\n")

assert numLinesRaw - numLinesClean == 14
assert num_lines_raw - num_lines_clean == 14
plt.close("all")

def test_wireframe3D(self):
Expand Down Expand Up @@ -257,7 +257,7 @@ def cc(arg):
xs = np.arange(0, 10, 0.4)
verts = []
zs = [0.0, 1.0, 2.0, 3.0]
for z in zs:
for _ in zs:
ys = np.random.rand(len(xs))
ys[0], ys[-1] = 0, 0
verts.append(list(zip(xs, ys)))
Expand Down Expand Up @@ -384,9 +384,9 @@ def test_line_no_markers(self):
# the baseline (raw) should have 20 points
# the clean version (clean) should have 2 points
# the difference in line numbers should therefore be 2
numLinesRaw = raw.count("\n")
numLinesClean = clean.count("\n")
assert numLinesRaw - numLinesClean == 18
num_lines_raw = raw.count("\n")
num_lines_clean = clean.count("\n")
assert num_lines_raw - num_lines_clean == 18
plt.close("all")

def test_no_line_markers(self):
Expand All @@ -410,9 +410,9 @@ def test_no_line_markers(self):
# the baseline (raw) should have 20 points
# the clean version (clean) should have 2 points
# the difference in line numbers should therefore be 2
numLinesRaw = raw.count("\n")
numLinesClean = clean.count("\n")
assert numLinesRaw - numLinesClean == 6
num_lines_raw = raw.count("\n")
num_lines_clean = clean.count("\n")
assert num_lines_raw - num_lines_clean == 6
plt.close("all")

def test_line_markers(self):
Expand All @@ -436,9 +436,9 @@ def test_line_markers(self):
# the baseline (raw) should have 20 points
# the clean version (clean) should have 2 points
# the difference in line numbers should therefore be 2
numLinesRaw = raw.count("\n")
numLinesClean = clean.count("\n")
assert numLinesRaw - numLinesClean == 6
num_lines_raw = raw.count("\n")
num_lines_clean = clean.count("\n")
assert num_lines_raw - num_lines_clean == 6
plt.close("all")

def test_sine(self):
Expand All @@ -459,9 +459,9 @@ def test_sine(self):
# the baseline (raw) should have 20 points
# the clean version (clean) should have 2 points
# the difference in line numbers should therefore be 2
numLinesRaw = raw.count("\n")
numLinesClean = clean.count("\n")
assert numLinesRaw - numLinesClean == 39
num_lines_raw = raw.count("\n")
num_lines_clean = clean.count("\n")
assert num_lines_raw - num_lines_clean == 39
plt.close("all")


Expand Down Expand Up @@ -510,9 +510,9 @@ def test_subplot(self):
# the baseline (raw) should have 20 points
# the clean version (clean) should have 2 points
# the difference in line numbers should therefore be 2
numLinesRaw = raw.count("\n")
numLinesClean = clean.count("\n")
assert numLinesRaw - numLinesClean == 36
num_lines_raw = raw.count("\n")
num_lines_clean = clean.count("\n")
assert num_lines_raw - num_lines_clean == 36
plt.close("all")


Expand All @@ -522,106 +522,106 @@ def test_ylog(self):
y = np.exp(x)

with plt.rc_context(rc=RC_PARAMS):
fig, ax = plt.subplots(1)
_, ax = plt.subplots(1)
ax.plot(x, y)
ax.set_yscale("log")
raw = get_tikz_code()
clean_figure()

clean = get_tikz_code()
numLinesRaw = raw.count("\n")
numLinesClean = clean.count("\n")
assert numLinesRaw - numLinesClean == 98
assert numLinesClean == 25
num_lines_raw = raw.count("\n")
num_lines_clean = clean.count("\n")
assert num_lines_raw - num_lines_clean == 98
assert num_lines_clean == 25
plt.close("all")

def test_xlog(self):
y = np.linspace(0, 3, 100)
x = np.exp(y)

with plt.rc_context(rc=RC_PARAMS):
fig, ax = plt.subplots(1)
_, ax = plt.subplots(1)
ax.plot(x, y)
ax.set_xscale("log")
raw = get_tikz_code()
clean_figure()

clean = get_tikz_code()
numLinesRaw = raw.count("\n")
numLinesClean = clean.count("\n")
assert numLinesRaw - numLinesClean == 98
assert numLinesClean == 25
num_lines_raw = raw.count("\n")
num_lines_clean = clean.count("\n")
assert num_lines_raw - num_lines_clean == 98
assert num_lines_clean == 25
plt.close("all")

def test_loglog(self):
x = np.exp(np.logspace(0, 5, 100))
y = np.exp(np.logspace(0, 5, 100))
x = np.exp(np.logspace(0.0, 1.5, 100))
y = np.exp(np.logspace(0.0, 1.5, 100))

with plt.rc_context(rc=RC_PARAMS):
fig, ax = plt.subplots(1)
_, ax = plt.subplots(1)
ax.plot(x, y)
ax.set_xscale("log")
ax.set_yscale("log")
raw = get_tikz_code()
clean_figure()

clean = get_tikz_code()
numLinesRaw = raw.count("\n")
numLinesClean = clean.count("\n")
assert numLinesRaw - numLinesClean == 99
assert numLinesClean == 27
num_lines_raw = raw.count("\n")
num_lines_clean = clean.count("\n")
assert num_lines_raw == 125
assert num_lines_clean == 27
plt.close("all")

def test_ylog_2(self):
x = np.arange(1, 100)
y = np.arange(1, 100)
with plt.rc_context(rc=RC_PARAMS):
fig, ax = plt.subplots(1)
_, ax = plt.subplots(1)
ax.plot(x, y)
ax.set_yscale("log")
raw = get_tikz_code()
clean_figure()

clean = get_tikz_code()
numLinesRaw = raw.count("\n")
numLinesClean = clean.count("\n")
assert numLinesRaw - numLinesClean == 51
assert numLinesClean == 71
num_lines_raw = raw.count("\n")
num_lines_clean = clean.count("\n")
assert num_lines_raw - num_lines_clean == 51
assert num_lines_clean == 71
plt.close("all")

def test_xlog_2(self):
x = np.arange(1, 100)
y = np.arange(1, 100)
with plt.rc_context(rc=RC_PARAMS):
fig, ax = plt.subplots(1)
_, ax = plt.subplots(1)
ax.plot(x, y)
ax.set_xscale("log")
raw = get_tikz_code()
clean_figure()

clean = get_tikz_code()
numLinesRaw = raw.count("\n")
numLinesClean = clean.count("\n")
assert numLinesRaw - numLinesClean == 51
assert numLinesClean == 71
num_lines_raw = raw.count("\n")
num_lines_clean = clean.count("\n")
assert num_lines_raw - num_lines_clean == 51
assert num_lines_clean == 71
plt.close("all")

def test_loglog_2(self):
x = np.arange(1, 100)
y = np.arange(1, 100)
with plt.rc_context(rc=RC_PARAMS):
fig, ax = plt.subplots(1)
_, ax = plt.subplots(1)
ax.plot(x, y)
ax.set_xscale("log")
ax.set_yscale("log")
raw = get_tikz_code()
clean_figure()

clean = get_tikz_code()
numLinesRaw = raw.count("\n")
numLinesClean = clean.count("\n")
assert numLinesRaw - numLinesClean == 97
assert numLinesClean == 27
num_lines_raw = raw.count("\n")
num_lines_clean = clean.count("\n")
assert num_lines_raw - num_lines_clean == 97
assert num_lines_clean == 27
plt.close("all")

def test_loglog_3(self):
Expand All @@ -639,9 +639,9 @@ def test_loglog_3(self):

clean_figure(fig)
clean = get_tikz_code()
numLinesRaw = raw.count("\n")
numLinesClean = clean.count("\n")
assert numLinesRaw - numLinesClean == 18
num_lines_raw = raw.count("\n")
num_lines_clean = clean.count("\n")
assert num_lines_raw - num_lines_clean == 18
plt.close("all")

def test_xlog_3(self):
Expand All @@ -658,9 +658,9 @@ def test_xlog_3(self):

clean_figure(fig)
clean = get_tikz_code()
numLinesRaw = raw.count("\n")
numLinesClean = clean.count("\n")
assert numLinesRaw - numLinesClean == 18
num_lines_raw = raw.count("\n")
num_lines_clean = clean.count("\n")
assert num_lines_raw - num_lines_clean == 18
plt.close("all")


Expand Down
4 changes: 3 additions & 1 deletion tests/test_hatch.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import pytest
from helpers import assert_equality


Expand Down Expand Up @@ -57,7 +58,8 @@ def plot():


def test():
assert_equality(plot, "test_hatch_reference.tex")
with pytest.warns(UserWarning):
assert_equality(plot, "test_hatch_reference.tex")


if __name__ == "__main__":
Expand Down

0 comments on commit d2af95f

Please sign in to comment.