Skip to content

Commit 3c1e08e

Browse files
authored
Merge pull request #444 from theRealSuperMario/fix/logscale
Fix/logscale
2 parents 3ca706e + 25b685b commit 3c1e08e

File tree

2 files changed

+148
-40
lines changed

2 files changed

+148
-40
lines changed

test/test_cleanfigure.py

Lines changed: 148 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -33,45 +33,6 @@ def test_plot(self):
3333
assert numLinesRaw - numLinesClean == 18
3434
plt.close("all")
3535

36-
def test_logplot(self):
37-
x = np.logspace(-3, 3, 20)
38-
y = np.logspace(-3, 3, 20)
39-
40-
with plt.rc_context(rc=RC_PARAMS):
41-
fig, ax = plt.subplots(1, 1, figsize=(5, 5))
42-
ax.plot(x, y)
43-
ax.set_xscale("log")
44-
ax.set_yscale("log")
45-
ax.set_ylim([10 ** (-2), 10 ** (2)])
46-
ax.set_xlim([10 ** (-2), 10 ** (2)])
47-
raw = get_tikz_code()
48-
49-
clean_figure(fig)
50-
clean = get_tikz_code()
51-
numLinesRaw = raw.count("\n")
52-
numLinesClean = clean.count("\n")
53-
assert numLinesRaw - numLinesClean == 11
54-
plt.close("all")
55-
56-
def test_semilogplot(self):
57-
x = np.logspace(-3, 3, 20)
58-
y = np.linspace(1, 100, 20)
59-
60-
with plt.rc_context(rc=RC_PARAMS):
61-
fig, ax = plt.subplots(1, 1, figsize=(5, 5))
62-
ax.plot(x, y)
63-
ax.set_xscale("log")
64-
ax.set_xlim([10 ** (-2), 10 ** (2)])
65-
ax.set_ylim([20, 80])
66-
raw = get_tikz_code()
67-
68-
clean_figure(fig)
69-
clean = get_tikz_code()
70-
numLinesRaw = raw.count("\n")
71-
numLinesClean = clean.count("\n")
72-
assert numLinesRaw - numLinesClean == 6
73-
plt.close("all")
74-
7536
def test_step(self):
7637
x = np.linspace(1, 100, 20)
7738
y = np.linspace(1, 100, 20)
@@ -556,6 +517,154 @@ def test_subplot(self):
556517
plt.close("all")
557518

558519

520+
class Test_logscale:
521+
def test_ylog(self):
522+
x = np.linspace(0, 3, 100)
523+
y = np.exp(x)
524+
525+
with plt.rc_context(rc=RC_PARAMS):
526+
fig, ax = plt.subplots(1)
527+
ax.plot(x, y)
528+
ax.set_yscale("log")
529+
raw = get_tikz_code()
530+
clean_figure()
531+
532+
clean = get_tikz_code()
533+
numLinesRaw = raw.count("\n")
534+
numLinesClean = clean.count("\n")
535+
assert numLinesRaw - numLinesClean == 98
536+
assert numLinesClean == 25
537+
plt.close("all")
538+
539+
def test_xlog(self):
540+
y = np.linspace(0, 3, 100)
541+
x = np.exp(y)
542+
543+
with plt.rc_context(rc=RC_PARAMS):
544+
fig, ax = plt.subplots(1)
545+
ax.plot(x, y)
546+
ax.set_xscale("log")
547+
raw = get_tikz_code()
548+
clean_figure()
549+
550+
clean = get_tikz_code()
551+
numLinesRaw = raw.count("\n")
552+
numLinesClean = clean.count("\n")
553+
assert numLinesRaw - numLinesClean == 98
554+
assert numLinesClean == 25
555+
plt.close("all")
556+
557+
def test_loglog(self):
558+
x = np.exp(np.logspace(0, 5, 100))
559+
y = np.exp(np.logspace(0, 5, 100))
560+
561+
with plt.rc_context(rc=RC_PARAMS):
562+
fig, ax = plt.subplots(1)
563+
ax.plot(x, y)
564+
ax.set_xscale("log")
565+
ax.set_yscale("log")
566+
raw = get_tikz_code()
567+
clean_figure()
568+
569+
clean = get_tikz_code()
570+
numLinesRaw = raw.count("\n")
571+
numLinesClean = clean.count("\n")
572+
assert numLinesRaw - numLinesClean == 98
573+
assert numLinesClean == 27
574+
plt.close("all")
575+
576+
def test_ylog_2(self):
577+
x = np.arange(1, 100)
578+
y = np.arange(1, 100)
579+
with plt.rc_context(rc=RC_PARAMS):
580+
fig, ax = plt.subplots(1)
581+
ax.plot(x, y)
582+
ax.set_yscale("log")
583+
raw = get_tikz_code()
584+
clean_figure()
585+
586+
clean = get_tikz_code()
587+
numLinesRaw = raw.count("\n")
588+
numLinesClean = clean.count("\n")
589+
assert numLinesRaw - numLinesClean == 51
590+
assert numLinesClean == 71
591+
plt.close("all")
592+
593+
def test_xlog_2(self):
594+
x = np.arange(1, 100)
595+
y = np.arange(1, 100)
596+
with plt.rc_context(rc=RC_PARAMS):
597+
fig, ax = plt.subplots(1)
598+
ax.plot(x, y)
599+
ax.set_xscale("log")
600+
raw = get_tikz_code()
601+
clean_figure()
602+
603+
clean = get_tikz_code()
604+
numLinesRaw = raw.count("\n")
605+
numLinesClean = clean.count("\n")
606+
assert numLinesRaw - numLinesClean == 51
607+
assert numLinesClean == 71
608+
plt.close("all")
609+
610+
def test_loglog_2(self):
611+
x = np.arange(1, 100)
612+
y = np.arange(1, 100)
613+
with plt.rc_context(rc=RC_PARAMS):
614+
fig, ax = plt.subplots(1)
615+
ax.plot(x, y)
616+
ax.set_xscale("log")
617+
ax.set_yscale("log")
618+
raw = get_tikz_code()
619+
clean_figure()
620+
621+
clean = get_tikz_code()
622+
numLinesRaw = raw.count("\n")
623+
numLinesClean = clean.count("\n")
624+
assert numLinesRaw - numLinesClean == 97
625+
assert numLinesClean == 27
626+
plt.close("all")
627+
628+
def test_loglog_3(self):
629+
x = np.logspace(-3, 3, 20)
630+
y = np.logspace(-3, 3, 20)
631+
632+
with plt.rc_context(rc=RC_PARAMS):
633+
fig, ax = plt.subplots(1, 1, figsize=(5, 5))
634+
ax.plot(x, y)
635+
ax.set_xscale("log")
636+
ax.set_yscale("log")
637+
ax.set_ylim([10 ** (-2), 10 ** (2)])
638+
ax.set_xlim([10 ** (-2), 10 ** (2)])
639+
raw = get_tikz_code()
640+
641+
clean_figure(fig)
642+
clean = get_tikz_code()
643+
numLinesRaw = raw.count("\n")
644+
numLinesClean = clean.count("\n")
645+
assert numLinesRaw - numLinesClean == 18
646+
plt.close("all")
647+
648+
def test_xlog_3(self):
649+
x = np.logspace(-3, 3, 20)
650+
y = np.linspace(1, 100, 20)
651+
652+
with plt.rc_context(rc=RC_PARAMS):
653+
fig, ax = plt.subplots(1, 1, figsize=(5, 5))
654+
ax.plot(x, y)
655+
ax.set_xscale("log")
656+
ax.set_xlim([10 ** (-2), 10 ** (2)])
657+
ax.set_ylim([20, 80])
658+
raw = get_tikz_code()
659+
660+
clean_figure(fig)
661+
clean = get_tikz_code()
662+
numLinesRaw = raw.count("\n")
663+
numLinesClean = clean.count("\n")
664+
assert numLinesRaw - numLinesClean == 18
665+
plt.close("all")
666+
667+
559668
def test_memory():
560669
plt.plot(np.arange(100000))
561670
clean_figure()

tikzplotlib/_cleanfigure.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,6 @@ def _cleanline(fighandle, axhandle, linehandle, target_resolution, scale_precisi
230230

231231
if not is3D:
232232
visual_data = _move_points_closer(xLim, yLim, visual_data)
233-
visual_data = _get_visual_data(axhandle, visual_data, is3D)
234233

235234
hasMarkers = not linehandle.get_marker() == "None"
236235
hasLines = not linehandle.get_linestyle() == "None"

0 commit comments

Comments
 (0)