Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6f24660

Browse files
committed
Filter out invalid value warnings in log scaling
Wrap all logscaling in ignore invalid values
1 parent 438aa08 commit 6f24660

1 file changed

Lines changed: 15 additions & 14 deletions

File tree

lib/matplotlib/scale.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -98,25 +98,26 @@ def __init__(self, nonpos='clip'):
9898
self._clip = {"clip": True, "mask": False}[nonpos]
9999

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

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

121122

122123
class InvertedLogTransformBase(Transform):

0 commit comments

Comments
 (0)