Skip to content

Commit 7cf0d8d

Browse files
test for using cleanfigure with subplots
1 parent 3473c1e commit 7cf0d8d

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

test/test_cleanfigure.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,34 @@ def test_sine(self):
486486
assert numLinesRaw - numLinesClean == 39
487487

488488

489+
class Test_subplots:
490+
def test_subplot(self):
491+
from tikzplotlib import get_tikz_code
492+
493+
x = np.linspace(1, 100, 20)
494+
y = np.linspace(1, 100, 20)
495+
496+
with plt.rc_context(rc=RC_PARAMS):
497+
fig, axes = plt.subplots(2, 2, figsize=(5, 5))
498+
plotstyles = [("-", "o"), ("-", "None"), ("None", "o"), ("--", "x")]
499+
for ax, style in zip(axes.ravel(), plotstyles):
500+
ax.plot(x, y, linestyle=style[0], marker=style[1])
501+
ax.set_ylim([20, 80])
502+
ax.set_xlim([20, 80])
503+
raw = get_tikz_code()
504+
505+
cleanfigure.cleanfigure(fig)
506+
clean = get_tikz_code()
507+
508+
# Use number of lines to test if it worked.
509+
# the baseline (raw) should have 20 points
510+
# the clean version (clean) should have 2 points
511+
# the difference in line numbers should therefore be 2
512+
numLinesRaw = raw.count("\n")
513+
numLinesClean = clean.count("\n")
514+
assert numLinesRaw - numLinesClean == 36
515+
516+
489517
def test_segmentVisible():
490518
"""test against matlab2tikz implementation
491519

0 commit comments

Comments
 (0)