Skip to content

Commit 37a72e2

Browse files
authored
Merge branch 'main' into fix-scatter-colors
2 parents 653b21b + 7f4d2d4 commit 37a72e2

File tree

5 files changed

+84
-82
lines changed

5 files changed

+84
-82
lines changed

src/tikzplotlib/_cleanfigure.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,18 +1280,17 @@ def _cross_lines(X1, X2, X3, X4):
12801280
:param X4: X4
12811281
:type X4: np.ndarray
12821282
"""
1283-
n = X2.shape[0]
1284-
Lambda = np.zeros((n, 2))
12851283
detA = -(X2[:, 0] - X1[:, 0]) * (X4[1] - X3[1]) + (X2[:, 1] - X1[:, 1]) * (
12861284
X4[0] - X3[0]
12871285
)
12881286

12891287
id_detA = detA != 0
12901288

1289+
n = X2.shape[0]
1290+
Lambda = np.zeros((n, 2))
12911291
if id_detA.any():
1292-
rhs = -X1.reshape((-1, 2)) + X3.reshape(
1293-
(-1, 2)
1294-
) # NOTE: watch out for broadcasting
1292+
# NOTE: watch out for broadcasting
1293+
rhs = -X1.reshape((-1, 2)) + X3.reshape((-1, 2))
12951294
Rotate = np.array([[0, -1], [1, 0]])
12961295
Lambda[id_detA, 0] = (rhs[id_detA, :] @ Rotate @ (X4 - X3).T) / detA[id_detA]
12971296
Lambda[id_detA, 1] = (

src/tikzplotlib/_line2d.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ def _table(obj, data): # noqa: C901
288288
with open(filepath, "w") as f:
289289
# No encoding handling required: plot_table is only ASCII
290290
f.write("".join(plot_table))
291-
content.append(rel_filepath)
291+
content.append(str(rel_filepath))
292292
else:
293293
content.extend(plot_table)
294294

src/tikzplotlib/_path.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def draw_path(data, path, draw_options=None, simplify=None):
2727
ff = data["float format"]
2828
xformat = "" if x_is_date else ff
2929
prev = None
30+
is_area = None
3031
for vert, code in path.iter_segments(simplify=simplify):
3132
# nschloe, Oct 2, 2015:
3233
# The transform call yields warnings and it is unclear why. Perhaps
@@ -199,12 +200,12 @@ def draw_pathcollection(data, obj):
199200
"visualization depends on={value \\thisrow{draw} \\as \\drawcolor}",
200201
"visualization depends on={value \\thisrow{fill} \\as \\fillcolor}",
201202
"scatter/@pre marker code/.code={%\n"
202-
" \\expanded{%\n"
203-
" \\noexpand\\definecolor{thispointdrawcolor}{RGB}{\\drawcolor}%\n"
204-
" \\noexpand\\definecolor{thispointfillcolor}{RGB}{\\fillcolor}%\n"
205-
" }%\n"
206-
" \\scope[draw=thispointdrawcolor, fill=thispointfillcolor]%\n"
207-
"}",
203+
+ " \\expanded{%\n"
204+
+ " \\noexpand\\definecolor{thispointdrawcolor}{RGB}{\\drawcolor}%\n"
205+
+ " \\noexpand\\definecolor{thispointfillcolor}{RGB}{\\fillcolor}%\n"
206+
+ " }%\n"
207+
+ " \\scope[draw=thispointdrawcolor, fill=thispointfillcolor]%\n"
208+
+ "}",
208209
"scatter/@post marker code/.code={%\n" " \\endscope\n" "}",
209210
]
210211
)
@@ -274,10 +275,10 @@ def draw_pathcollection(data, obj):
274275
draw_options.extend(
275276
[
276277
"visualization depends on="
277-
"{\\thisrow{sizedata} \\as\\perpointmarksize}",
278+
+ "{\\thisrow{sizedata} \\as\\perpointmarksize}",
278279
"scatter",
279280
"scatter/@pre marker code/.append style="
280-
"{/tikz/mark size=\\perpointmarksize}",
281+
+ "{/tikz/mark size=\\perpointmarksize}",
281282
# "scatter/@post marker code/.style={}"
282283
]
283284
)

tests/test_cleanfigure.py

Lines changed: 67 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ def test_plot(self):
2828
# the baseline (raw) should have 20 points
2929
# the clean version (clean) should have 2 points
3030
# the difference in line numbers should therefore be 2
31-
numLinesRaw = raw.count("\n")
32-
numLinesClean = clean.count("\n")
33-
assert numLinesRaw - numLinesClean == 18
31+
num_lines_raw = raw.count("\n")
32+
num_lines_clean = clean.count("\n")
33+
assert num_lines_raw - num_lines_clean == 18
3434
plt.close("all")
3535

3636
def test_step(self):
@@ -50,7 +50,7 @@ def test_scatter(self):
5050
x = np.linspace(1, 100, 20)
5151
y = np.linspace(1, 100, 20)
5252
with plt.rc_context(rc=RC_PARAMS):
53-
fig, ax = plt.subplots(1, 1, figsize=(5, 5))
53+
_, ax = plt.subplots(1, 1, figsize=(5, 5))
5454
ax.scatter(x, y)
5555
ax.set_ylim([20, 80])
5656
ax.set_xlim([20, 80])
@@ -63,9 +63,9 @@ def test_scatter(self):
6363
# the baseline (raw) should have 20 points
6464
# the clean version (clean) should have 2 points
6565
# the difference in line numbers should therefore be 2
66-
numLinesRaw = raw.count("\n")
67-
numLinesClean = clean.count("\n")
68-
assert numLinesRaw - numLinesClean == 6
66+
num_lines_raw = raw.count("\n")
67+
num_lines_clean = clean.count("\n")
68+
assert num_lines_raw - num_lines_clean == 6
6969
plt.close("all")
7070

7171
def test_bar(self):
@@ -113,9 +113,9 @@ def test_plot3d(self):
113113
clean = get_tikz_code()
114114

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

121121
def test_scatter3d(self):
@@ -139,10 +139,10 @@ def test_scatter3d(self):
139139
clean = get_tikz_code()
140140

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

145-
assert numLinesRaw - numLinesClean == 14
145+
assert num_lines_raw - num_lines_clean == 14
146146
plt.close("all")
147147

148148
def test_wireframe3D(self):
@@ -257,7 +257,7 @@ def cc(arg):
257257
xs = np.arange(0, 10, 0.4)
258258
verts = []
259259
zs = [0.0, 1.0, 2.0, 3.0]
260-
for z in zs:
260+
for _ in zs:
261261
ys = np.random.rand(len(xs))
262262
ys[0], ys[-1] = 0, 0
263263
verts.append(list(zip(xs, ys)))
@@ -384,9 +384,9 @@ def test_line_no_markers(self):
384384
# the baseline (raw) should have 20 points
385385
# the clean version (clean) should have 2 points
386386
# the difference in line numbers should therefore be 2
387-
numLinesRaw = raw.count("\n")
388-
numLinesClean = clean.count("\n")
389-
assert numLinesRaw - numLinesClean == 18
387+
num_lines_raw = raw.count("\n")
388+
num_lines_clean = clean.count("\n")
389+
assert num_lines_raw - num_lines_clean == 18
390390
plt.close("all")
391391

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

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

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

467467

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

518518

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

524524
with plt.rc_context(rc=RC_PARAMS):
525-
fig, ax = plt.subplots(1)
525+
_, ax = plt.subplots(1)
526526
ax.plot(x, y)
527527
ax.set_yscale("log")
528528
raw = get_tikz_code()
529529
clean_figure()
530530

531531
clean = get_tikz_code()
532-
numLinesRaw = raw.count("\n")
533-
numLinesClean = clean.count("\n")
534-
assert numLinesRaw - numLinesClean == 98
535-
assert numLinesClean == 25
532+
num_lines_raw = raw.count("\n")
533+
num_lines_clean = clean.count("\n")
534+
assert num_lines_raw - num_lines_clean == 98
535+
assert num_lines_clean == 25
536536
plt.close("all")
537537

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

542542
with plt.rc_context(rc=RC_PARAMS):
543-
fig, ax = plt.subplots(1)
543+
_, ax = plt.subplots(1)
544544
ax.plot(x, y)
545545
ax.set_xscale("log")
546546
raw = get_tikz_code()
547547
clean_figure()
548548

549549
clean = get_tikz_code()
550-
numLinesRaw = raw.count("\n")
551-
numLinesClean = clean.count("\n")
552-
assert numLinesRaw - numLinesClean == 98
553-
assert numLinesClean == 25
550+
num_lines_raw = raw.count("\n")
551+
num_lines_clean = clean.count("\n")
552+
assert num_lines_raw - num_lines_clean == 98
553+
assert num_lines_clean == 25
554554
plt.close("all")
555555

556556
def test_loglog(self):
557-
x = np.exp(np.logspace(0, 5, 100))
558-
y = np.exp(np.logspace(0, 5, 100))
557+
x = np.exp(np.logspace(0.0, 1.5, 100))
558+
y = np.exp(np.logspace(0.0, 1.5, 100))
559559

560560
with plt.rc_context(rc=RC_PARAMS):
561-
fig, ax = plt.subplots(1)
561+
_, ax = plt.subplots(1)
562562
ax.plot(x, y)
563563
ax.set_xscale("log")
564564
ax.set_yscale("log")
565565
raw = get_tikz_code()
566566
clean_figure()
567567

568568
clean = get_tikz_code()
569-
numLinesRaw = raw.count("\n")
570-
numLinesClean = clean.count("\n")
571-
assert numLinesRaw - numLinesClean == 99
572-
assert numLinesClean == 27
569+
num_lines_raw = raw.count("\n")
570+
num_lines_clean = clean.count("\n")
571+
assert num_lines_raw == 125
572+
assert num_lines_clean == 27
573573
plt.close("all")
574574

575575
def test_ylog_2(self):
576576
x = np.arange(1, 100)
577577
y = np.arange(1, 100)
578578
with plt.rc_context(rc=RC_PARAMS):
579-
fig, ax = plt.subplots(1)
579+
_, ax = plt.subplots(1)
580580
ax.plot(x, y)
581581
ax.set_yscale("log")
582582
raw = get_tikz_code()
583583
clean_figure()
584584

585585
clean = get_tikz_code()
586-
numLinesRaw = raw.count("\n")
587-
numLinesClean = clean.count("\n")
588-
assert numLinesRaw - numLinesClean == 51
589-
assert numLinesClean == 71
586+
num_lines_raw = raw.count("\n")
587+
num_lines_clean = clean.count("\n")
588+
assert num_lines_raw - num_lines_clean == 51
589+
assert num_lines_clean == 71
590590
plt.close("all")
591591

592592
def test_xlog_2(self):
593593
x = np.arange(1, 100)
594594
y = np.arange(1, 100)
595595
with plt.rc_context(rc=RC_PARAMS):
596-
fig, ax = plt.subplots(1)
596+
_, ax = plt.subplots(1)
597597
ax.plot(x, y)
598598
ax.set_xscale("log")
599599
raw = get_tikz_code()
600600
clean_figure()
601601

602602
clean = get_tikz_code()
603-
numLinesRaw = raw.count("\n")
604-
numLinesClean = clean.count("\n")
605-
assert numLinesRaw - numLinesClean == 51
606-
assert numLinesClean == 71
603+
num_lines_raw = raw.count("\n")
604+
num_lines_clean = clean.count("\n")
605+
assert num_lines_raw - num_lines_clean == 51
606+
assert num_lines_clean == 71
607607
plt.close("all")
608608

609609
def test_loglog_2(self):
610610
x = np.arange(1, 100)
611611
y = np.arange(1, 100)
612612
with plt.rc_context(rc=RC_PARAMS):
613-
fig, ax = plt.subplots(1)
613+
_, ax = plt.subplots(1)
614614
ax.plot(x, y)
615615
ax.set_xscale("log")
616616
ax.set_yscale("log")
617617
raw = get_tikz_code()
618618
clean_figure()
619619

620620
clean = get_tikz_code()
621-
numLinesRaw = raw.count("\n")
622-
numLinesClean = clean.count("\n")
623-
assert numLinesRaw - numLinesClean == 97
624-
assert numLinesClean == 27
621+
num_lines_raw = raw.count("\n")
622+
num_lines_clean = clean.count("\n")
623+
assert num_lines_raw - num_lines_clean == 97
624+
assert num_lines_clean == 27
625625
plt.close("all")
626626

627627
def test_loglog_3(self):
@@ -639,9 +639,9 @@ def test_loglog_3(self):
639639

640640
clean_figure(fig)
641641
clean = get_tikz_code()
642-
numLinesRaw = raw.count("\n")
643-
numLinesClean = clean.count("\n")
644-
assert numLinesRaw - numLinesClean == 18
642+
num_lines_raw = raw.count("\n")
643+
num_lines_clean = clean.count("\n")
644+
assert num_lines_raw - num_lines_clean == 18
645645
plt.close("all")
646646

647647
def test_xlog_3(self):
@@ -658,9 +658,9 @@ def test_xlog_3(self):
658658

659659
clean_figure(fig)
660660
clean = get_tikz_code()
661-
numLinesRaw = raw.count("\n")
662-
numLinesClean = clean.count("\n")
663-
assert numLinesRaw - numLinesClean == 18
661+
num_lines_raw = raw.count("\n")
662+
num_lines_clean = clean.count("\n")
663+
assert num_lines_raw - num_lines_clean == 18
664664
plt.close("all")
665665

666666

tests/test_hatch.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import pytest
12
from helpers import assert_equality
23

34

@@ -57,7 +58,8 @@ def plot():
5758

5859

5960
def test():
60-
assert_equality(plot, "test_hatch_reference.tex")
61+
with pytest.warns(UserWarning):
62+
assert_equality(plot, "test_hatch_reference.tex")
6163

6264

6365
if __name__ == "__main__":

0 commit comments

Comments
 (0)