Skip to content

Commit

Permalink
Merge pull request #10480 from dstansby/logscale-np-warning
Browse files Browse the repository at this point in the history
Filter out invalid value warnings in log scaling
  • Loading branch information
jklymak committed Mar 6, 2018
2 parents 8184e1f + 6f24660 commit 5cb2205
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions lib/matplotlib/scale.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,25 +98,26 @@ def __init__(self, nonpos='clip'):
self._clip = {"clip": True, "mask": False}[nonpos]

def transform_non_affine(self, a):
# Ignore invalid values due to nans being passed to the transform
with np.errstate(divide="ignore", invalid="ignore"):
out = np.log(a)
out /= np.log(self.base)
if self._clip:
# SVG spec says that conforming viewers must support values up
# to 3.4e38 (C float); however experiments suggest that Inkscape
# (which uses cairo for rendering) runs into cairo's 24-bit limit
# (which is apparently shared by Agg).
# Ghostscript (used for pdf rendering appears to overflow even
# earlier, with the max value around 2 ** 15 for the tests to pass.
# On the other hand, in practice, we want to clip beyond
# np.log10(np.nextafter(0, 1)) ~ -323
# so 1000 seems safe.
out[a <= 0] = -1000
out /= np.log(self.base)
if self._clip:
# SVG spec says that conforming viewers must support values up
# to 3.4e38 (C float); however experiments suggest that
# Inkscape (which uses cairo for rendering) runs into cairo's
# 24-bit limit (which is apparently shared by Agg).
# Ghostscript (used for pdf rendering appears to overflow even
# earlier, with the max value around 2 ** 15 for the tests to
# pass. On the other hand, in practice, we want to clip beyond
# np.log10(np.nextafter(0, 1)) ~ -323
# so 1000 seems safe.
out[a <= 0] = -1000
return out

def __str__(self):
return "{}({!r})".format(type(self).__name__,
"clip" if self._clip else "mask")
return "{}({!r})".format(
type(self).__name__, "clip" if self._clip else "mask")


class InvertedLogTransformBase(Transform):
Expand Down

0 comments on commit 5cb2205

Please sign in to comment.