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

Skip to content

Log axvline #1247

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 3 commits into from
Sep 18, 2012
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions lib/matplotlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1075,6 +1075,7 @@ def tk_window_focus():
'matplotlib.tests.test_patches',
'matplotlib.tests.test_pickle',
'matplotlib.tests.test_rcparams',
'matplotlib.tests.test_scale',
'matplotlib.tests.test_simplification',
'matplotlib.tests.test_spines',
'matplotlib.tests.test_text',
Expand Down
79 changes: 47 additions & 32 deletions lib/matplotlib/scale.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
from __future__ import print_function
import textwrap

import numpy as np
from numpy import ma
MaskedArray = ma.MaskedArray

from cbook import dedent
from ticker import NullFormatter, ScalarFormatter, LogFormatterMathtext, Formatter
from ticker import NullLocator, LogLocator, AutoLocator, SymmetricalLogLocator, FixedLocator
from ticker import is_decade
from transforms import Transform, IdentityTransform
from matplotlib.cbook import dedent
from matplotlib.ticker import (NullFormatter, ScalarFormatter,
LogFormatterMathtext)
from matplotlib.ticker import (NullLocator, LogLocator, AutoLocator,
SymmetricalLogLocator)
from matplotlib.transforms import Transform, IdentityTransform
from matplotlib import docstring


class ScaleBase(object):
"""
The base class for all scales.
Expand All @@ -31,15 +32,15 @@ def get_transform(self):
Return the :class:`~matplotlib.transforms.Transform` object
associated with this scale.
"""
raise NotImplementedError
raise NotImplementedError()

def set_default_locators_and_formatters(self, axis):
"""
Set the :class:`~matplotlib.ticker.Locator` and
:class:`~matplotlib.ticker.Formatter` objects on the given
axis to match this scale.
"""
raise NotImplementedError
raise NotImplementedError()

def limit_range_for_scale(self, vmin, vmax, minpos):
"""
Expand All @@ -51,6 +52,7 @@ def limit_range_for_scale(self, vmin, vmax, minpos):
"""
return vmin, vmax


class LinearScale(ScaleBase):
"""
The default linear scale.
Expand Down Expand Up @@ -90,10 +92,12 @@ def _mask_non_positives(a):
return ma.MaskedArray(a, mask=mask)
return a


def _clip_non_positives(a):
a[a <= 0.0] = 1e-300
return a


class LogScale(ScaleBase):
"""
A standard logarithmic scale. Care is taken so non-positive
Expand All @@ -115,21 +119,21 @@ class LogTransformBase(Transform):
input_dims = 1
output_dims = 1
is_separable = True

has_inverse = True

def __init__(self, nonpos):
Transform.__init__(self)
if nonpos == 'mask':
self._handle_nonpos = _mask_non_positives
else:
self._handle_nonpos = _clip_non_positives


class Log10Transform(LogTransformBase):
base = 10.0

def transform(self, a):
def transform_non_affine(self, a):
a = self._handle_nonpos(a * 10.0)
if isinstance(a, MaskedArray):
if isinstance(a, ma.MaskedArray):
return ma.log10(a)
return np.log10(a)

Expand All @@ -140,9 +144,10 @@ class InvertedLog10Transform(Transform):
input_dims = 1
output_dims = 1
is_separable = True
has_inverse = True
base = 10.0

def transform(self, a):
def transform_non_affine(self, a):
return ma.power(10.0, a) / 10.0

def inverted(self):
Expand All @@ -151,9 +156,9 @@ def inverted(self):
class Log2Transform(LogTransformBase):
base = 2.0

def transform(self, a):
def transform_non_affine(self, a):
a = self._handle_nonpos(a * 2.0)
if isinstance(a, MaskedArray):
if isinstance(a, ma.MaskedArray):
return ma.log(a) / np.log(2)
return np.log2(a)

Expand All @@ -164,9 +169,10 @@ class InvertedLog2Transform(Transform):
input_dims = 1
output_dims = 1
is_separable = True
has_inverse = True
base = 2.0

def transform(self, a):
def transform_non_affine(self, a):
return ma.power(2.0, a) / 2.0

def inverted(self):
Expand All @@ -175,9 +181,9 @@ def inverted(self):
class NaturalLogTransform(LogTransformBase):
base = np.e

def transform(self, a):
def transform_non_affine(self, a):
a = self._handle_nonpos(a * np.e)
if isinstance(a, MaskedArray):
if isinstance(a, ma.MaskedArray):
return ma.log(a)
return np.log(a)

Expand All @@ -188,9 +194,10 @@ class InvertedNaturalLogTransform(Transform):
input_dims = 1
output_dims = 1
is_separable = True
has_inverse = True
base = np.e

def transform(self, a):
def transform_non_affine(self, a):
return ma.power(np.e, a) / np.e

def inverted(self):
Expand All @@ -200,7 +207,8 @@ class LogTransform(Transform):
input_dims = 1
output_dims = 1
is_separable = True

has_inverse = True

def __init__(self, base, nonpos):
Transform.__init__(self)
self.base = base
Expand All @@ -209,9 +217,9 @@ def __init__(self, base, nonpos):
else:
self._handle_nonpos = _clip_non_positives

def transform(self, a):
def transform_non_affine(self, a):
a = self._handle_nonpos(a * self.base)
if isinstance(a, MaskedArray):
if isinstance(a, ma.MaskedArray):
return ma.log(a) / np.log(self.base)
return np.log(a) / np.log(self.base)

Expand All @@ -222,18 +230,18 @@ class InvertedLogTransform(Transform):
input_dims = 1
output_dims = 1
is_separable = True

has_inverse = True

def __init__(self, base):
Transform.__init__(self)
self.base = base

def transform(self, a):
def transform_non_affine(self, a):
return ma.power(self.base, a) / self.base

def inverted(self):
return LogScale.LogTransform(self.base)



def __init__(self, axis, **kwargs):
"""
*basex*/*basey*:
Expand Down Expand Up @@ -316,7 +324,8 @@ class SymmetricalLogTransform(Transform):
input_dims = 1
output_dims = 1
is_separable = True

has_inverse = True

def __init__(self, base, linthresh, linscale):
Transform.__init__(self)
self.base = base
Expand All @@ -325,7 +334,7 @@ def __init__(self, base, linthresh, linscale):
self._linscale_adj = (linscale / (1.0 - self.base ** -1))
self._log_base = np.log(base)

def transform(self, a):
def transform_non_affine(self, a):
sign = np.sign(a)
masked = ma.masked_inside(a, -self.linthresh, self.linthresh, copy=False)
log = sign * self.linthresh * (
Expand All @@ -344,7 +353,8 @@ class InvertedSymmetricalLogTransform(Transform):
input_dims = 1
output_dims = 1
is_separable = True

has_inverse = True

def __init__(self, base, linthresh, linscale):
Transform.__init__(self)
symlog = SymmetricalLogScale.SymmetricalLogTransform(base, linthresh, linscale)
Expand All @@ -354,7 +364,7 @@ def __init__(self, base, linthresh, linscale):
self.linscale = linscale
self._linscale_adj = (linscale / (1.0 - self.base ** -1))

def transform(self, a):
def transform_non_affine(self, a):
sign = np.sign(a)
masked = ma.masked_inside(a, -self.invlinthresh, self.invlinthresh, copy=False)
exp = sign * self.linthresh * (
Expand Down Expand Up @@ -434,17 +444,19 @@ def get_transform(self):
return self._transform



_scale_mapping = {
'linear' : LinearScale,
'log' : LogScale,
'symlog' : SymmetricalLogScale
}


def get_scale_names():
names = _scale_mapping.keys()
names.sort()
return names


def scale_factory(scale, axis, **kwargs):
"""
Return a scale class by name.
Expand All @@ -462,6 +474,7 @@ def scale_factory(scale, axis, **kwargs):
scale_factory.__doc__ = dedent(scale_factory.__doc__) % \
{'names': " | ".join(get_scale_names())}


def register_scale(scale_class):
"""
Register a new kind of scale.
Expand All @@ -470,6 +483,7 @@ def register_scale(scale_class):
"""
_scale_mapping[scale_class.name] = scale_class


def get_scale_docs():
"""
Helper function for generating docstrings related to scales.
Expand All @@ -486,6 +500,7 @@ def get_scale_docs():
docs.append("")
return "\n".join(docs)


docstring.interpd.update(
scale = ' | '.join([repr(x) for x in get_scale_names()]),
scale_docs = get_scale_docs().strip(),
Expand Down
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading