matplotlib.colors.Colormap
-
class matplotlib.colors.Colormap(name, N=256)
[source] -
Bases:
object
Baseclass for all scalar to RGBA mappings.
Typically, Colormap instances are used to convert data values (floats) from the interval
[0, 1]
to the RGBA color that the respective Colormap represents. For scaling of data into the[0, 1]
interval seematplotlib.colors.Normalize
. Subclasses ofmatplotlib.cm.ScalarMappable
make heavy use of thisdata -> normalize -> map-to-color
processing chain.Parameters: -
namestr
-
The name of the colormap.
-
Nint
-
The number of rgb quantization levels.
-
__call__(self, X, alpha=None, bytes=False)
[source] -
Parameters: -
Xfloat or int, ndarray or scalar
-
The data value(s) to convert to RGBA. For floats, X should be in the interval
[0.0, 1.0]
to return the RGBA valuesX*100
percent along the Colormap line. For integers, X should be in the interval[0, Colormap.N)
to return RGBA values indexed from the Colormap with indexX
. -
alphafloat or array-like or None
-
Alpha must be a scalar between 0 and 1, a sequence of such floats with shape matching X, or None.
-
bytesbool
-
If False (default), the returned RGBA values will be floats in the interval
[0, 1]
otherwise they will be uint8s in the interval[0, 255]
.
Returns: - Tuple of RGBA values if X is scalar, otherwise an array of
-
RGBA values with a shape of X.shape + (4, ).
-
-
__copy__(self)
[source]
-
__dict__ = mappingproxy({'__module__': 'matplotlib.colors', '__doc__': '\n Baseclass for all scalar to RGBA mappings.\n\n Typically, Colormap instances are used to convert data values (floats)\n from the interval ``[0, 1]`` to the RGBA color that the respective\n Colormap represents. For scaling of data into the ``[0, 1]`` interval see\n `matplotlib.colors.Normalize`. Subclasses of `matplotlib.cm.ScalarMappable`\n make heavy use of this ``data -> normalize -> map-to-color`` processing\n chain.\n ', '__init__': <function Colormap.__init__>, '__call__': <function Colormap.__call__>, '__copy__': <function Colormap.__copy__>, 'get_bad': <function Colormap.get_bad>, 'set_bad': <function Colormap.set_bad>, 'get_under': <function Colormap.get_under>, 'set_under': <function Colormap.set_under>, 'get_over': <function Colormap.get_over>, 'set_over': <function Colormap.set_over>, 'set_extremes': <function Colormap.set_extremes>, 'with_extremes': <function Colormap.with_extremes>, '_set_extremes': <function Colormap._set_extremes>, '_init': <function Colormap._init>, 'is_gray': <function Colormap.is_gray>, '_resample': <function Colormap._resample>, 'reversed': <function Colormap.reversed>, '_repr_png_': <function Colormap._repr_png_>, '_repr_html_': <function Colormap._repr_html_>, 'copy': <function Colormap.copy>, '__dict__': <attribute '__dict__' of 'Colormap' objects>, '__weakref__': <attribute '__weakref__' of 'Colormap' objects>})
-
__init__(self, name, N=256)
[source] -
Parameters: -
namestr
-
The name of the colormap.
-
Nint
-
The number of rgb quantization levels.
-
-
__module__ = 'matplotlib.colors'
-
__weakref__
-
list of weak references to the object (if defined)
-
colorbar_extend
-
When this colormap exists on a scalar mappable and colorbar_extend is not False, colorbar creation will pick up
colorbar_extend
as the default value for theextend
keyword in thematplotlib.colorbar.Colorbar
constructor.
-
copy(self)
[source] -
Return a copy of the colormap.
-
get_bad(self)
[source] -
Get the color for masked values.
-
get_over(self)
[source] -
Get the color for high out-of-range values.
-
get_under(self)
[source] -
Get the color for low out-of-range values.
-
is_gray(self)
[source] -
Return whether the colormap is grayscale.
-
reversed(self, name=None)
[source] -
Return a reversed instance of the Colormap.
Note
This function is not implemented for base class.
Parameters: -
namestr, optional
-
The name for the reversed colormap. If it's None the name will be the name of the parent colormap + "_r".
-
-
set_bad(self, color='k', alpha=None)
[source] -
Set the color for masked values.
-
set_extremes(self, *, bad=None, under=None, over=None)
[source] -
Set the colors for masked (bad) values and, when
norm.clip = False
, low (under) and high (over) out-of-range values.
-
set_over(self, color='k', alpha=None)
[source] -
Set the color for high out-of-range values.
-
set_under(self, color='k', alpha=None)
[source] -
Set the color for low out-of-range values.
-
with_extremes(self, *, bad=None, under=None, over=None)
[source] -
Return a copy of the colormap, for which the colors for masked (bad) values and, when
norm.clip = False
, low (under) and high (over) out-of-range values, have been set accordingly.
-
Examples using matplotlib.colors.Colormap
© 2012–2021 Matplotlib Development Team. All rights reserved.
Licensed under the Matplotlib License Agreement.
https://matplotlib.org/3.4.1/api/_as_gen/matplotlib.colors.Colormap.html