-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Fix InvertedLog10Transform.inverted() #10242
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
a31be02
b2dfa40
b5652bf
8418f09
c4f25e9
aea1d94
dc1f60b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -93,7 +93,7 @@ class LogTransformBase(Transform): | |
is_separable = True | ||
has_inverse = True | ||
|
||
def __init__(self, nonpos): | ||
def __init__(self, nonpos='mask'): | ||
Transform.__init__(self) | ||
self._clip = {"clip": True, "mask": False}[nonpos] | ||
|
||
|
@@ -114,6 +114,8 @@ def transform_non_affine(self, a): | |
out[a <= 0] = -1000 | ||
return out | ||
|
||
def __str__(self): | ||
return "{}({!r})".format(type(self).__name__, "clip" if self._clip else "mask") | ||
|
||
class InvertedLogTransformBase(Transform): | ||
input_dims = 1 | ||
|
@@ -124,6 +126,9 @@ class InvertedLogTransformBase(Transform): | |
def transform_non_affine(self, a): | ||
return ma.power(self.base, a) | ||
|
||
def __str__(self): | ||
return "{}()".format(type(self).__name__) | ||
|
||
|
||
class Log10Transform(LogTransformBase): | ||
base = 10.0 | ||
|
@@ -168,7 +173,7 @@ def inverted(self): | |
|
||
|
||
class LogTransform(LogTransformBase): | ||
def __init__(self, base, nonpos): | ||
def __init__(self, base, nonpos='mask'): | ||
LogTransformBase.__init__(self, nonpos) | ||
self.base = base | ||
|
||
|
@@ -448,7 +453,7 @@ class LogitTransform(Transform): | |
is_separable = True | ||
has_inverse = True | ||
|
||
def __init__(self, nonpos): | ||
def __init__(self, nonpos='mask'): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this needs changing to 'clip' instead of 'mask' There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For consistency, I used the same default for LogitTransform (and LogisticTransform) as for LogitScale, which already uses 'mask'. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
Transform.__init__(self) | ||
self._nonpos = nonpos | ||
self._clip = {"clip": True, "mask": False}[nonpos] | ||
|
@@ -465,6 +470,9 @@ def transform_non_affine(self, a): | |
def inverted(self): | ||
return LogisticTransform(self._nonpos) | ||
|
||
def __str__(self): | ||
return "{}({!r})".format(type(self).__name__, "clip" if self._clip else "mask") | ||
|
||
|
||
class LogisticTransform(Transform): | ||
input_dims = 1 | ||
|
@@ -483,6 +491,9 @@ def transform_non_affine(self, a): | |
def inverted(self): | ||
return LogitTransform(self._nonpos) | ||
|
||
def __str__(self): | ||
return "{}({!r})".format(type(self).__name__, self._nonpos) | ||
|
||
|
||
class LogitScale(ScaleBase): | ||
""" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,6 +74,18 @@ def test_extra_kwargs_raise(): | |
ax.set_yscale('log', nonpos='mask') | ||
|
||
|
||
def test_logscale_invert_transform(): | ||
fig, ax = plt.subplots() | ||
ax.set_yscale('log') | ||
# get transformation from data to axes | ||
tform = (ax.transAxes + ax.transData.inverted()).inverted() | ||
|
||
def test_logscale_transform_repr(): | ||
fig, ax = plt.subplots() | ||
ax.set_yscale('log') | ||
s = repr(ax.transData) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. show we There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ping @fkloosterman - can this test do more than just make sure it runs? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you mean something like: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @fkloosterman yes something like that. Note, the pep8 checker will complain about the last line unless you put spaces around the |
||
|
||
|
||
@image_comparison(baseline_images=['logscale_nonpos_values'], remove_text=True, | ||
extensions=['png'], style='mpl20') | ||
def test_logscale_nonpos_values(): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably default to 'clip' as this is the default else where.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right, LogScale uses clip as default and so should LogTransform. Fixed in the PR.