8000 Fix InvertedLog10Transform.inverted() by fkloosterman · Pull Request #10242 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

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

Merged
merged 7 commits into from
Jan 29, 2018
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions lib/matplotlib/scale.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class LogTransformBase(Transform):
is_separable = True
has_inverse = True

def __init__(self, nonpos):
def __init__(self, nonpos='mask'):
Copy link
Member

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.

Copy link
Contributor Author

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.

Transform.__init__(self)
self._clip = {"clip": True, "mask": False}[nonpos]

Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -448,7 +453,7 @@ class LogitTransform(Transform):
is_separable = True
has_inverse = True

def __init__(self, nonpos):
def __init__(self, nonpos='mask'):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this needs changing to 'clip' instead of 'mask'

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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'.

Copy link
Member

Choose a reason for hiding this comment

The 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]
Expand All @@ -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
Expand All @@ -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):
"""
Expand Down
12 changes: 12 additions & 0 deletions lib/matplotlib/tests/test_scale.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

show we assert anything there?

Copy link
Member

Choose a reason for hiding this comment

The 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?

Copy link
Contributor Author
@fkloosterman fkloosterman Jan 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you mean something like:
s = repr(matplotlib.scale.Log10Transform(nonpos='clip'))
assert s=="Log10Transform('clip')"

Copy link
Member

Choose a reason for hiding this comment

The 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 == operator:
assert s == "Log10Transform('clip')"



@image_comparison(baseline_images=['logscale_nonpos_values'], remove_text=True,
extensions=['png'], style='mpl20')
def test_logscale_nonpos_values():
Expand Down
0