matplotlib.scale

Scales define the distribution of data values on an axis, e.g. a log scaling.

They are attached to an Axis and hold a Transform, which is responsible for the actual data transformation.

See also axes.Axes.set_xscale and the scales examples in the documentation.

class matplotlib.scale.FuncScale(axis, functions)[source]

Bases: matplotlib.scale.ScaleBase

Provide an arbitrary scale with user-supplied function for the axis.

Parameters:
axisAxis

The axis for the scale.

functions(callable, callable)

two-tuple of the forward and inverse functions for the scale. The forward function must be monotonic.

Both functions must have the signature:

def forward(values: array-like) -> array-like
get_transform(self)[source]

Return the FuncTransform associated with this scale.

name = 'function'
set_default_locators_and_formatters(self, axis)[source]

Set the locators and formatters of axis to instances suitable for this scale.

class matplotlib.scale.FuncScaleLog(axis, functions, base=10)[source]

Bases: matplotlib.scale.LogScale

Provide an arbitrary scale with user-supplied function for the axis and then put on a logarithmic axes.

Parameters:
axismatplotlib.axis.Axis

The axis for the scale.

functions(callable, callable)

two-tuple of the forward and inverse functions for the scale. The forward function must be monotonic.

Both functions must have the signature:

def forward(values: array-like) -> array-like
basefloat

logarithmic base of the scale (default = 10)

property base
get_transform(self)[source]

Return the Transform associated with this scale.

name = 'functionlog'
class matplotlib.scale.FuncTransform(forward, inverse)[source]

Bases: matplotlib.transforms.Transform

A simple transform that takes and arbitrary function for the forward and inverse transform.

Parameters:
forwardcallable

The forward function for the transform. This function must have an inverse and, for best behavior, be monotonic. It must have the signature:

def forward(values: array-like) -> array-like
inversecallable

The inverse of the forward function. Signature as forward.

has_inverse = True
input_dims = 1
inverted(self)[source]

Return the corresponding inverse transformation.

It holds x == self.inverted().transform(self.transform(x)).

The return value of this method should be treated as temporary. An update to self does not cause a corresponding update to its inverted copy.

is_separable = True
output_dims = 1
transform_non_affine(self, values)[source]

Performs only the non-affine part of the transformation.

transform(values) is always equivalent to transform_affine(transform_non_affine(values)).

In non-affine transformations, this is generally equivalent to transform(values). In affine transformations, this is always a no-op.

Parameters:
valuesarray

The input values as NumPy array of length input_dims or shape (N x input_dims).

Returns:
valuesarray

The output values as NumPy array of length input_dims or shape (N x output_dims), depending on the input.

class matplotlib.scale.InvertedLog10Transform(**kwargs)[source]

Bases: matplotlib.scale.InvertedLogTransformBase

[Deprecated]

Notes

Deprecated since version 3.1:

base = 10.0
has_inverse = True
inverted(self)[source]

Return the corresponding inverse transformation.

It holds x == self.inverted().transform(self.transform(x)).

The return value of this method should be treated as temporary. An update to self does not cause a corresponding update to its inverted copy.

class matplotlib.scale.InvertedLog2Transform(**kwargs)[source]

Bases: matplotlib.scale.InvertedLogTransformBase

[Deprecated]

Notes

Deprecated since version 3.1:

base = 2.0
has_inverse = True
inverted(self)[source]

Return the corresponding inverse transformation.

It holds x == self.inverted().transform(self.transform(x)).

The return value of this method should be treated as temporary. An update to self does not cause a corresponding update to its inverted copy.

class matplotlib.scale.InvertedLogTransform(base)[source]

Bases: matplotlib.scale.InvertedLogTransformBase

Creates a new TransformNode.

Parameters:
shorthand_namestr

A string representing the "name" of the transform. The name carries no significance other than to improve the readability of str(transform) when DEBUG=True.

has_inverse = True
input_dims = 1
inverted(self)[source]

Return the corresponding inverse transformation.

It holds x == self.inverted().transform(self.transform(x)).

The return value of this method should be treated as temporary. An update to self does not cause a corresponding update to its inverted copy.

output_dims = 1
transform_non_affine(self, a)[source]

Performs only the non-affine part of the transformation.

transform(values) is always equivalent to transform_affine(transform_non_affine(values)).

In non-affine transformations, this is generally equivalent to transform(values). In affine transformations, this is always a no-op.

Parameters:
valuesarray

The input values as NumPy array of length input_dims or shape (N x input_dims).

Returns:
valuesarray

The output values as NumPy array of length input_dims or shape (N x output_dims), depending on the input.

class matplotlib.scale.InvertedLogTransformBase(**kwargs)[source]

Bases: matplotlib.transforms.Transform

[Deprecated]

Notes

Deprecated since version 3.1:

input_dims = 1
is_separable = True
output_dims = 1
transform_non_affine(self, a)[source]

Performs only the non-affine part of the transformation.

transform(values) is always equivalent to transform_affine(transform_non_affine(values)).

In non-affine transformations, this is generally equivalent to transform(values). In affine transformations, this is always a no-op.

Parameters:
valuesarray

The input values as NumPy array of length input_dims or shape (N x input_dims).

Returns:
valuesarray

The output values as NumPy array of length input_dims or shape (N x output_dims), depending on the input.

class matplotlib.scale.InvertedNaturalLogTransform(**kwargs)[source]

Bases: matplotlib.scale.InvertedLogTransformBase

[Deprecated]

Notes

Deprecated since version 3.1:

base = 2.718281828459045
has_inverse = True
inverted(self)[source]

Return the corresponding inverse transformation.

It holds x == self.inverted().transform(self.transform(x)).

The return value of this method should be treated as temporary. An update to self does not cause a corresponding update to its inverted copy.

class matplotlib.scale.InvertedSymmetricalLogTransform(base, linthresh, linscale)[source]

Bases: matplotlib.transforms.Transform

Creates a new TransformNode.

Parameters:
shorthand_namestr

A string representing the "name" of the transform. The name carries no significance other than to improve the readability of str(transform) when DEBUG=True.

has_inverse = True
input_dims = 1
inverted(self)[source]

Return the corresponding inverse transformation.

It holds x == self.inverted().transform(self.transform(x)).

The return value of this method should be treated as temporary. An update to self does not cause a corresponding update to its inverted copy.

is_separable = True
output_dims = 1
transform_non_affine(self, a)[source]

Performs only the non-affine part of the transformation.

transform(values) is always equivalent to transform_affine(transform_non_affine(values)).

In non-affine transformations, this is generally equivalent to transform(values). In affine transformations, this is always a no-op.

Parameters:
valuesarray

The input values as NumPy array of length input_dims or shape (N x input_dims).

Returns:
valuesarray

The output values as NumPy array of length input_dims or shape (N x output_dims), depending on the input.

class matplotlib.scale.LinearScale(axis, **kwargs)[source]

Bases: matplotlib.scale.ScaleBase

The default linear scale.

get_transform(self)[source]

Return the transform for linear scaling, which is just the IdentityTransform.

name = 'linear'
set_default_locators_and_formatters(self, axis)[source]

Set the locators and formatters of axis to instances suitable for this scale.

class matplotlib.scale.Log10Transform(**kwargs)[source]

Bases: matplotlib.scale.LogTransformBase

[Deprecated]

Notes

Deprecated since version 3.1:

base = 10.0
has_inverse = True
inverted(self)[source]

Return the corresponding inverse transformation.

It holds x == self.inverted().transform(self.transform(x)).

The return value of this method should be treated as temporary. An update to self does not cause a corresponding update to its inverted copy.

class matplotlib.scale.Log2Transform(**kwargs)[source]

Bases: matplotlib.scale.LogTransformBase

[Deprecated]

Notes

Deprecated since version 3.1:

base = 2.0
has_inverse = True
inverted(self)[source]

Return the corresponding inverse transformation.

It holds x == self.inverted().transform(self.transform(x)).

The return value of this method should be treated as temporary. An update to self does not cause a corresponding update to its inverted copy.

class matplotlib.scale.LogScale(axis, **kwargs)[source]

Bases: matplotlib.scale.ScaleBase

A standard logarithmic scale. Care is taken to only plot positive values.

Parameters:
axisAxis

The axis for the scale.

basex, baseyfloat, default: 10

The base of the logarithm.

nonposx, nonposy{'clip', 'mask'}, default: 'clip'

Determines the behavior for non-positive values. They can either be masked as invalid, or clipped to a very small positive number.

subsx, subsysequence of int, default: None

Where to place the subticks between each major tick. For example, in a log10 scale: [2, 3, 4, 5, 6, 7, 8, 9] will place 8 logarithmically spaced minor ticks between each major tick.

class InvertedLog10Transform(**kwargs)

Bases: matplotlib.scale.InvertedLogTransformBase

[Deprecated]

Notes

Deprecated since version 3.1:

base = 10.0
has_inverse = True
inverted(self)

Return the corresponding inverse transformation.

It holds x == self.inverted().transform(self.transform(x)).

The return value of this method should be treated as temporary. An update to self does not cause a corresponding update to its inverted copy.

class InvertedLog2Transform(**kwargs)

Bases: matplotlib.scale.InvertedLogTransformBase

[Deprecated]

Notes

Deprecated since version 3.1:

base = 2.0
has_inverse = True
inverted(self)

Return the corresponding inverse transformation.

It holds x == self.inverted().transform(self.transform(x)).

The return value of this method should be treated as temporary. An update to self does not cause a corresponding update to its inverted copy.

class InvertedLogTransform(base)

Bases: matplotlib.scale.InvertedLogTransformBase

Creates a new TransformNode.

Parameters:
shorthand_namestr

A string representing the "name" of the transform. The name carries no significance other than to improve the readability of str(transform) when DEBUG=True.

has_inverse = True
input_dims = 1
inverted(self)

Return the corresponding inverse transformation.

It holds x == self.inverted().transform(self.transform(x)).

The return value of this method should be treated as temporary. An update to self does not cause a corresponding update to its inverted copy.

output_dims = 1
transform_non_affine(self, a)

Performs only the non-affine part of the transformation.

transform(values) is always equivalent to transform_affine(transform_non_affine(values)).

In non-affine transformations, this is generally equivalent to transform(values). In affine transformations, this is always a no-op.

Parameters:
valuesarray

The input values as NumPy array of length input_dims or shape (N x input_dims).

Returns:
valuesarray

The output values as NumPy array of length input_dims or shape (N x output_dims), depending on the input.

class InvertedNaturalLogTransform(**kwargs)

Bases: matplotlib.scale.InvertedLogTransformBase

[Deprecated]

Notes

Deprecated since version 3.1:

base = 2.718281828459045
has_inverse = True
inverted(self)

Return the corresponding inverse transformation.

It holds x == self.inverted().transform(self.transform(x)).

The return value of this method should be treated as temporary. An update to self does not cause a corresponding update to its inverted copy.

class Log10Transform(**kwargs)

Bases: matplotlib.scale.LogTransformBase

[Deprecated]

Notes

Deprecated since version 3.1:

base = 10.0
has_inverse = True
inverted(self)

Return the corresponding inverse transformation.

It holds x == self.inverted().transform(self.transform(x)).

The return value of this method should be treated as temporary. An update to self does not cause a corresponding update to its inverted copy.

class Log2Transform(**kwargs)

Bases: matplotlib.scale.LogTransformBase

[Deprecated]

Notes

Deprecated since version 3.1:

base = 2.0
has_inverse = True
inverted(self)

Return the corresponding inverse transformation.

It holds x == self.inverted().transform(self.transform(x)).

The return value of this method should be treated as temporary. An update to self does not cause a corresponding update to its inverted copy.

class LogTransform(base, nonpos='clip')

Bases: matplotlib.transforms.Transform

Creates a new TransformNode.

Parameters:
shorthand_namestr

A string representing the "name" of the transform. The name carries no significance other than to improve the readability of str(transform) when DEBUG=True.

has_inverse = True
input_dims = 1
inverted(self)

Return the corresponding inverse transformation.

It holds x == self.inverted().transform(self.transform(x)).

The return value of this method should be treated as temporary. An update to self does not cause a corresponding update to its inverted copy.

is_separable = True
output_dims = 1
transform_non_affine(self, a)

Performs only the non-affine part of the transformation.

transform(values) is always equivalent to transform_affine(transform_non_affine(values)).

In non-affine transformations, this is generally equivalent to transform(values). In affine transformations, this is always a no-op.

Parameters:
valuesarray

The input values as NumPy array of length input_dims or shape (N x input_dims).

Returns:
valuesarray

The output values as NumPy array of length input_dims or shape (N x output_dims), depending on the input.

class LogTransformBase(**kwargs)

Bases: matplotlib.transforms.Transform

[Deprecated]

Notes

Deprecated since version 3.1:

input_dims = 1
is_separable = True
output_dims = 1
transform_non_affine(self, a)

Performs only the non-affine part of the transformation.

transform(values) is always equivalent to transform_affine(transform_non_affine(values)).

In non-affine transformations, this is generally equivalent to transform(values). In affine transformations, this is always a no-op.

Parameters:
valuesarray

The input values as NumPy array of length input_dims or shape (N x input_dims).

Returns:
valuesarray

The output values as NumPy array of length input_dims or shape (N x output_dims), depending on the input.

class NaturalLogTransform(**kwargs)

Bases: matplotlib.scale.LogTransformBase

[Deprecated]

Notes

Deprecated since version 3.1:

base = 2.718281828459045
has_inverse = True
inverted(self)

Return the corresponding inverse transformation.

It holds x == self.inverted().transform(self.transform(x)).

The return value of this method should be treated as temporary. An update to self does not cause a corresponding update to its inverted copy.

property base
get_transform(self)[source]

Return the LogTransform associated with this scale.

limit_range_for_scale(self, vmin, vmax, minpos)[source]

Limit the domain to positive values.

name = 'log'
set_default_locators_and_formatters(self, axis)[source]

Set the locators and formatters of axis to instances suitable for this scale.

class matplotlib.scale.LogTransform(base, nonpos='clip')[source]

Bases: matplotlib.transforms.Transform

Creates a new TransformNode.

Parameters:
shorthand_namestr

A string representing the "name" of the transform. The name carries no significance other than to improve the readability of str(transform) when DEBUG=True.

has_inverse = True
input_dims = 1
inverted(self)[source]

Return the corresponding inverse transformation.

It holds x == self.inverted().transform(self.transform(x)).

The return value of this method should be treated as temporary. An update to self does not cause a corresponding update to its inverted copy.

is_separable = True
output_dims = 1
transform_non_affine(self, a)[source]

Performs only the non-affine part of the transformation.

transform(values) is always equivalent to transform_affine(transform_non_affine(values)).

In non-affine transformations, this is generally equivalent to transform(values). In affine transformations, this is always a no-op.

Parameters:
valuesarray

The input values as NumPy array of length input_dims or shape (N x input_dims).

Returns:
valuesarray

The output values as NumPy array of length input_dims or shape (N x output_dims), depending on the input.

class matplotlib.scale.LogTransformBase(**kwargs)[source]

Bases: matplotlib.transforms.Transform

[Deprecated]

Notes

Deprecated since version 3.1:

input_dims = 1
is_separable = True
output_dims = 1
transform_non_affine(self, a)[source]

Performs only the non-affine part of the transformation.

transform(values) is always equivalent to transform_affine(transform_non_affine(values)).

In non-affine transformations, this is generally equivalent to transform(values). In affine transformations, this is always a no-op.

Parameters:
valuesarray

The input values as NumPy array of length input_dims or shape (N x input_dims).

Returns:
valuesarray

The output values as NumPy array of length input_dims or shape (N x output_dims), depending on the input.

class matplotlib.scale.LogisticTransform(nonpos='mask')[source]

Bases: matplotlib.transforms.Transform

Creates a new TransformNode.

Parameters:
shorthand_namestr

A string representing the "name" of the transform. The name carries no significance other than to improve the readability of str(transform) when DEBUG=True.

has_inverse = True
input_dims = 1
inverted(self)[source]

Return the corresponding inverse transformation.

It holds x == self.inverted().transform(self.transform(x)).

The return value of this method should be treated as temporary. An update to self does not cause a corresponding update to its inverted copy.

is_separable = True
output_dims = 1
transform_non_affine(self, a)[source]

logistic transform (base 10)

class matplotlib.scale.LogitScale(axis, nonpos='mask', *, one_half='\frac{1}{2}', use_overline=False)[source]

Bases: matplotlib.scale.ScaleBase

Logit scale for data between zero and one, both excluded.

This scale is similar to a log scale close to zero and to one, and almost linear around 0.5. It maps the interval ]0, 1[ onto ]-infty, +infty[.

Parameters:
axismatplotlib.axis.Axis

Currently unused.

nonpos{'mask', 'clip'}

Determines the behavior for values beyond the open interval ]0, 1[. They can either be masked as invalid, or clipped to a number very close to 0 or 1.

use_overlinebool, default: False

Indicate the usage of survival notation (overline{x}) in place of standard notation (1-x) for probability close to one.

one_halfstr, default: r"frac{1}{2}"

The string used for ticks formatter to represent 1/2.

get_transform(self)[source]

Return the LogitTransform associated with this scale.

limit_range_for_scale(self, vmin, vmax, minpos)[source]

Limit the domain to values between 0 and 1 (excluded).

name = 'logit'
set_default_locators_and_formatters(self, axis)[source]

Set the locators and formatters of axis to instances suitable for this scale.

class matplotlib.scale.LogitTransform(nonpos='mask')[source]

Bases: matplotlib.transforms.Transform

Creates a new TransformNode.

Parameters:
shorthand_namestr

A string representing the "name" of the transform. The name carries no significance other than to improve the readability of str(transform) when DEBUG=True.

has_inverse = True
input_dims = 1
inverted(self)[source]

Return the corresponding inverse transformation.

It holds x == self.inverted().transform(self.transform(x)).

The return value of this method should be treated as temporary. An update to self does not cause a corresponding update to its inverted copy.

is_separable = True
output_dims = 1
transform_non_affine(self, a)[source]

logit transform (base 10), masked or clipped

class matplotlib.scale.NaturalLogTransform(**kwargs)[source]

Bases: matplotlib.scale.LogTransformBase

[Deprecated]

Notes

Deprecated since version 3.1:

base = 2.718281828459045
has_inverse = True
inverted(self)[source]

Return the corresponding inverse transformation.

It holds x == self.inverted().transform(self.transform(x)).

The return value of this method should be treated as temporary. An update to self does not cause a corresponding update to its inverted copy.

class matplotlib.scale.ScaleBase(axis, **kwargs)[source]

Bases: object

The base class for all scales.

Scales are separable transformations, working on a single dimension.

Any subclasses will want to override:

And optionally:

Construct a new scale.

Notes

The following note is for scale implementors.

For back-compatibility reasons, scales take an Axis object as first argument. However, this argument should not be used: a single scale object should be usable by multiple Axises at the same time.

get_transform(self)[source]

Return the Transform object associated with this scale.

limit_range_for_scale(self, vmin, vmax, minpos)[source]

Returns the range vmin, vmax, possibly limited to the domain supported by this scale.

minpos should be the minimum positive value in the data. This is used by log scales to determine a minimum value.

set_default_locators_and_formatters(self, axis)[source]

Set the locators and formatters of axis to instances suitable for this scale.

class matplotlib.scale.SymmetricalLogScale(axis, **kwargs)[source]

Bases: matplotlib.scale.ScaleBase

The symmetrical logarithmic scale is logarithmic in both the positive and negative directions from the origin.

Since the values close to zero tend toward infinity, there is a need to have a range around zero that is linear. The parameter linthresh allows the user to specify the size of this range (-linthresh, linthresh).

Parameters:
basex, baseyfloat

The base of the logarithm. Defaults to 10.

linthreshx, linthreshyfloat

Defines the range (-x, x), within which the plot is linear. This avoids having the plot go to infinity around zero. Defaults to 2.

subsx, subsysequence of int

Where to place the subticks between each major tick. For example, in a log10 scale: [2, 3, 4, 5, 6, 7, 8, 9] will place 8 logarithmically spaced minor ticks between each major tick.

linscalex, linscaleyfloat, optional

This allows the linear range (-linthresh, linthresh) to be stretched relative to the logarithmic range. Its value is the number of decades to use for each half of the linear range. For example, when linscale == 1.0 (the default), the space used for the positive and negative halves of the linear range will be equal to one decade in the logarithmic range.

Construct a new scale.

Notes

The following note is for scale implementors.

For back-compatibility reasons, scales take an Axis object as first argument. However, this argument should not be used: a single scale object should be usable by multiple Axises at the same time.

class InvertedSymmetricalLogTransform(base, linthresh, linscale)

Bases: matplotlib.transforms.Transform

Creates a new TransformNode.

Parameters:
shorthand_namestr

A string representing the "name" of the transform. The name carries no significance other than to improve the readability of str(transform) when DEBUG=True.

has_inverse = True
input_dims = 1
inverted(self)

Return the corresponding inverse transformation.

It holds x == self.inverted().transform(self.transform(x)).

The return value of this method should be treated as temporary. An update to self does not cause a corresponding update to its inverted copy.

is_separable = True
output_dims = 1
transform_non_affine(self, a)

Performs only the non-affine part of the transformation.

transform(values) is always equivalent to transform_affine(transform_non_affine(values)).

In non-affine transformations, this is generally equivalent to transform(values). In affine transformations, this is always a no-op.

Parameters:
valuesarray

The input values as NumPy array of length input_dims or shape (N x input_dims).

Returns:
valuesarray

The output values as NumPy array of length input_dims or shape (N x output_dims), depending on the input.

class SymmetricalLogTransform(base, linthresh, linscale)

Bases: matplotlib.transforms.Transform

Creates a new TransformNode.

Parameters:
shorthand_namestr

A string representing the "name" of the transform. The name carries no significance other than to improve the readability of str(transform) when DEBUG=True.

has_inverse = True
input_dims = 1
inverted(self)

Return the corresponding inverse transformation.

It holds x == self.inverted().transform(self.transform(x)).

The return value of this method should be treated as temporary. An update to self does not cause a corresponding update to its inverted copy.

is_separable = True
output_dims = 1
transform_non_affine(self, a)

Performs only the non-affine part of the transformation.

transform(values) is always equivalent to transform_affine(transform_non_affine(values)).

In non-affine transformations, this is generally equivalent to transform(values). In affine transformations, this is always a no-op.

Parameters:
valuesarray

The input values as NumPy array of length input_dims or shape (N x input_dims).

Returns:
valuesarray

The output values as NumPy array of length input_dims or shape (N x output_dims), depending on the input.

get_transform(self)[source]

Return the SymmetricalLogTransform associated with this scale.

name = 'symlog'
set_default_locators_and_formatters(self, axis)[source]

Set the locators and formatters of axis to instances suitable for this scale.

class matplotlib.scale.SymmetricalLogTransform(base, linthresh, linscale)[source]

Bases: matplotlib.transforms.Transform

Creates a new TransformNode.

Parameters:
shorthand_namestr

A string representing the "name" of the transform. The name carries no significance other than to improve the readability of str(transform) when DEBUG=True.

has_inverse = True
input_dims = 1
inverted(self)[source]

Return the corresponding inverse transformation.

It holds x == self.inverted().transform(self.transform(x)).

The return value of this method should be treated as temporary. An update to self does not cause a corresponding update to its inverted copy.

is_separable = True
output_dims = 1
transform_non_affine(self, a)[source]

Performs only the non-affine part of the transformation.

transform(values) is always equivalent to transform_affine(transform_non_affine(values)).

In non-affine transformations, this is generally equivalent to transform(values). In affine transformations, this is always a no-op.

Parameters:
valuesarray

The input values as NumPy array of length input_dims or shape (N x input_dims).

Returns:
valuesarray

The output values as NumPy array of length input_dims or shape (N x output_dims), depending on the input.

matplotlib.scale.get_scale_docs()[source]

[Deprecated] Helper function for generating docstrings related to scales.

Notes

Deprecated since version 3.1: get_scale_docs() is considered private API since 3.1 and will be removed from the public API in 3.3.

matplotlib.scale.get_scale_names()[source]

Return the names of the available scales.

matplotlib.scale.register_scale(scale_class)[source]

Register a new kind of scale.

Parameters:
scale_classsubclass of ScaleBase

The scale to register.

matplotlib.scale.scale_factory(scale, axis, **kwargs)[source]

Return a scale class by name.

Parameters:
scale{'function', 'functionlog', 'linear', 'log', 'logit', 'symlog'}
axismatplotlib.axis.Axis