Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b05becd

Browse filesBrowse files
authored
Merge pull request #10242 from fkloosterman/logtransform
Fix InvertedLog10Transform.inverted()
2 parents 8650c2d + dc1f60b commit b05becd
Copy full SHA for b05becd

File tree

Expand file treeCollapse file tree

2 files changed

+40
-4
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+40
-4
lines changed

‎lib/matplotlib/scale.py

Copy file name to clipboardExpand all lines: lib/matplotlib/scale.py
+17-3Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class LogTransformBase(Transform):
9393
is_separable = True
9494
has_inverse = True
9595

96-
def __init__(self, nonpos):
96+
def __init__(self, nonpos='clip'):
9797
Transform.__init__(self)
9898
self._clip = {"clip": True, "mask": False}[nonpos]
9999

@@ -114,6 +114,10 @@ def transform_non_affine(self, a):
114114
out[a <= 0] = -1000
115115
return out
116116

117+
def __str__(self):
118+
return "{}({!r})".format(type(self).__name__,
119+
"clip" if self._clip else "mask")
120+
117121

118122
class InvertedLogTransformBase(Transform):
119123
input_dims = 1
@@ -124,6 +128,9 @@ class InvertedLogTransformBase(Transform):
124128
def transform_non_affine(self, a):
125129
return ma.power(self.base, a)
126130

131+
def __str__(self):
132+
return "{}()".format(type(self).__name__)
133+
127134

128135
class Log10Transform(LogTransformBase):
129136
base = 10.0
@@ -168,7 +175,7 @@ def inverted(self):
168175

169176

170177
class LogTransform(LogTransformBase):
171-
def __init__(self, base, nonpos):
178+
def __init__(self, base, nonpos='clip'):
172179
LogTransformBase.__init__(self, nonpos)
173180
self.base = base
174181

@@ -448,7 +455,7 @@ class LogitTransform(Transform):
448455
is_separable = True
449456
has_inverse = True
450457

451-
def __init__(self, nonpos):
458+
def __init__(self, nonpos='mask'):
452459
Transform.__init__(self)
453460
self._nonpos = nonpos
454461
self._clip = {"clip": True, "mask": False}[nonpos]
@@ -465,6 +472,10 @@ def transform_non_affine(self, a):
465472
def inverted(self):
466473
return LogisticTransform(self._nonpos)
467474

475+
def __str__(self):
476+
return "{}({!r})".format(type(self).__name__,
477+
"clip" if self._clip else "mask")
478+
468479

469480
class LogisticTransform(Transform):
470481
input_dims = 1
@@ -483,6 +494,9 @@ def transform_non_affine(self, a):
483494
def inverted(self):
484495
return LogitTransform(self._nonpos)
485496

497+
def __str__(self):
498+
return "{}({!r})".format(type(self).__name__, self._nonpos)
499+
486500

487501
class LogitScale(ScaleBase):
488502
"""

‎lib/matplotlib/tests/test_scale.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_scale.py
+23-1Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
from __future__ import print_function
1+
from __future__ import print_function, unicode_literals
22

33
from matplotlib.testing.decorators import image_comparison
44
import matplotlib.pyplot as plt
5+
from matplotlib.scale import Log10Transform, InvertedLog10Transform
56
import numpy as np
67
import io
78
import pytest
@@ -74,6 +75,27 @@ def test_extra_kwargs_raise():
7475
ax.set_yscale('log', nonpos='mask')
7576

7677

78+
def test_logscale_invert_transform():
79+
fig, ax = plt.subplots()
80+
ax.set_yscale('log')
81+
# get transformation from data to axes
82+
tform = (ax.transAxes + ax.transData.inverted()).inverted()
83+
84+
# direct test of log transform inversion
85+
assert isinstance(Log10Transform().inverted(), InvertedLog10Transform)
86+
87+
88+
def test_logscale_transform_repr():
89+
# check that repr of log transform succeeds
90+
fig, ax = plt.subplots()
91+
ax.set_yscale('log')
92+
s = repr(ax.transData)
93+
94+
# check that repr of log transform returns correct string
95+
s = repr(Log10Transform(nonpos='clip'))
96+
assert s == "Log10Transform({!r})".format('clip')
97+
98+
7799
@image_comparison(baseline_images=['logscale_nonpos_values'], remove_text=True,
78100
extensions=['png'], style='mpl20')
79101
def test_logscale_nonpos_values():

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.