MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / LogTransform

Class LogTransform

lib/matplotlib/scale.py:318–356  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

316
317
318class LogTransform(Transform):
319 input_dims = output_dims = 1
320
321 def __init__(self, base, nonpositive='clip'):
322 super().__init__()
323 if base <= 0 or base == 1:
324 raise ValueError('The log base cannot be <= 0 or == 1')
325 self.base = base
326 self._clip = _api.getitem_checked(
327 {"clip": True, "mask": False}, nonpositive=nonpositive)
328 self._log_funcs = {np.e: np.log, 2: np.log2, 10: np.log10}
329
330 def __str__(self):
331 return "{}(base={}, nonpositive={!r})".format(
332 type(self).__name__, self.base, "clip" if self._clip else "mask")
333
334 def transform_non_affine(self, values):
335 # Ignore invalid values due to nans being passed to the transform.
336 with np.errstate(divide="ignore", invalid="ignore"):
337 log_func = self._log_funcs.get(self.base)
338 if log_func:
339 out = log_func(values)
340 else:
341 out = np.log(values) / np.log(self.base)
342 if self._clip:
343 # SVG spec says that conforming viewers must support values up
344 # to 3.4e38 (C float); however experiments suggest that
345 # Inkscape (which uses cairo for rendering) runs into cairo's
346 # 24-bit limit (which is apparently shared by Agg).
347 # Ghostscript (used for pdf rendering appears to overflow even
348 # earlier, with the max value around 2 ** 15 for the tests to
349 # pass. On the other hand, in practice, we want to clip beyond
350 # np.log10(np.nextafter(0, 1)) ~ -323
351 # so 1000 seems safe.
352 out[values <= 0] = -1000
353 return out
354
355 def inverted(self):
356 return InvertedLogTransform(self.base)
357
358
359class InvertedLogTransform(Transform):

Callers 5

invertedMethod · 0.85
__init__Method · 0.85
__init__Method · 0.85

Calls

no outgoing calls

Tested by 2

Used in the wild real call sites across dependent graphs

searching dependent graphs…