Skip to content

Commit 9f1c5db

Browse files
Add test_cleanfigure:Test_logscale
1 parent 0a83d86 commit 9f1c5db

File tree

1 file changed

+109
-0
lines changed

1 file changed

+109
-0
lines changed

test/test_cleanfigure.py

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,115 @@ def test_subplot(self):
556556
plt.close("all")
557557

558558

559+
class Test_logscale:
560+
def test_ylog(self):
561+
x = np.linspace(0, 3, 100)
562+
y = np.exp(x)
563+
564+
with plt.rc_context(rc=RC_PARAMS):
565+
fig, ax = plt.subplots(1)
566+
ax.plot(x, y)
567+
ax.set_yscale("log")
568+
raw = get_tikz_code()
569+
clean_figure()
570+
571+
clean = get_tikz_code()
572+
numLinesRaw = raw.count("\n")
573+
numLinesClean = clean.count("\n")
574+
assert numLinesRaw - numLinesClean == 98
575+
assert numLinesClean == 25
576+
plt.close("all")
577+
578+
def test_xlog(self):
579+
y = np.linspace(0, 3, 100)
580+
x = np.exp(y)
581+
582+
with plt.rc_context(rc=RC_PARAMS):
583+
fig, ax = plt.subplots(1)
584+
ax.plot(x, y)
585+
ax.set_xscale("log")
586+
raw = get_tikz_code()
587+
clean_figure()
588+
589+
clean = get_tikz_code()
590+
numLinesRaw = raw.count("\n")
591+
numLinesClean = clean.count("\n")
592+
assert numLinesRaw - numLinesClean == 98
593+
assert numLinesClean == 25
594+
plt.close("all")
595+
596+
def test_loglog(self):
597+
x = np.exp(np.logspace(0, 5, 100))
598+
y = np.exp(np.logspace(0, 5, 100))
599+
600+
with plt.rc_context(rc=RC_PARAMS):
601+
fig, ax = plt.subplots(1)
602+
ax.plot(x, y)
603+
ax.set_xscale("log")
604+
ax.set_yscale("log")
605+
raw = get_tikz_code()
606+
clean_figure()
607+
608+
clean = get_tikz_code()
609+
numLinesRaw = raw.count("\n")
610+
numLinesClean = clean.count("\n")
611+
assert numLinesRaw - numLinesClean == 98
612+
assert numLinesClean == 27
613+
plt.close("all")
614+
615+
def test_ylog_2(self):
616+
x = np.arange(1, 100)
617+
y = np.arange(1, 100)
618+
with plt.rc_context(rc=RC_PARAMS):
619+
fig, ax = plt.subplots(1)
620+
ax.plot(x, y)
621+
ax.set_yscale("log")
622+
raw = get_tikz_code()
623+
clean_figure()
624+
625+
clean = get_tikz_code()
626+
numLinesRaw = raw.count("\n")
627+
numLinesClean = clean.count("\n")
628+
assert numLinesRaw - numLinesClean == 51
629+
assert numLinesClean == 71
630+
plt.close("all")
631+
632+
def test_xlog_2(self):
633+
x = np.arange(1, 100)
634+
y = np.arange(1, 100)
635+
with plt.rc_context(rc=RC_PARAMS):
636+
fig, ax = plt.subplots(1)
637+
ax.plot(x, y)
638+
ax.set_xscale("log")
639+
raw = get_tikz_code()
640+
clean_figure()
641+
642+
clean = get_tikz_code()
643+
numLinesRaw = raw.count("\n")
644+
numLinesClean = clean.count("\n")
645+
assert numLinesRaw - numLinesClean == 51
646+
assert numLinesClean == 71
647+
plt.close("all")
648+
649+
def test_loglog_2(self):
650+
x = np.arange(1, 100)
651+
y = np.arange(1, 100)
652+
with plt.rc_context(rc=RC_PARAMS):
653+
fig, ax = plt.subplots(1)
654+
ax.plot(x, y)
655+
ax.set_xscale("log")
656+
ax.set_yscale("log")
657+
raw = get_tikz_code()
658+
clean_figure()
659+
660+
clean = get_tikz_code()
661+
numLinesRaw = raw.count("\n")
662+
numLinesClean = clean.count("\n")
663+
assert numLinesRaw - numLinesClean == 97
664+
assert numLinesClean == 27
665+
plt.close("all")
666+
667+
559668
def test_memory():
560669
plt.plot(np.arange(100000))
561670
clean_figure()

0 commit comments

Comments
 (0)