colors
For a visual representation of the matplotlib colormaps, see the ?Color? section in the gallery.
matplotlib.colors
A module for converting numbers or color arguments to RGB or RGBA
RGB and RGBA are sequences of, respectively, 3 or 4 floats in the range 0-1.
This module includes functions and classes for color specification conversions, and for mapping numbers to colors in a 1-D array of colors called a colormap. Colormapping typically involves two steps: a data array is first mapped onto the range 0-1 using an instance of Normalize
or of a subclass; then this number in the 0-1 range is mapped to a color using an instance of a subclass of Colormap
. Two are provided here: LinearSegmentedColormap
, which is used to generate all the built-in colormap instances, but is also useful for making custom colormaps, and ListedColormap
, which is used for generating a custom colormap from a list of color specifications.
The module also provides a single instance, colorConverter, of the ColorConverter
class providing methods for converting single color specifications or sequences of them to RGB or RGBA.
Commands which take color arguments can use several formats to specify the colors. For the basic built-in colors, you can use a single letter
- b: blue
- g: green
- r: red
- c: cyan
- m: magenta
- y: yellow
- k: black
- w: white
Gray shades can be given as a string encoding a float in the 0-1 range, e.g.:
color = '0.75'
For a greater range of colors, you have two options. You can specify the color using an html hex string, as in:
color = '#eeefff'
or you can pass an R , G , B tuple, where each of R , G , B are in the range [0,1].
Finally, legal html names for colors, like ?red?, ?burlywood? and ?chartreuse? are supported.
-
class matplotlib.colors.BoundaryNorm(boundaries, ncolors, clip=False)
-
Bases:
matplotlib.colors.Normalize
Generate a colormap index based on discrete intervals.
Unlike
Normalize
orLogNorm
,BoundaryNorm
maps values to integers instead of to the interval 0-1.Mapping to the 0-1 interval could have been done via piece-wise linear interpolation, but using integers seems simpler, and reduces the number of conversions back and forth between integer and floating point.
- boundaries
- a monotonically increasing sequence
- ncolors
- number of colors in the colormap to be used
If:
b[i] <= v < b[i+1]
then v is mapped to color j; as i varies from 0 to len(boundaries)-2, j goes from 0 to ncolors-1.
Out-of-range values are mapped to -1 if low and ncolors if high; these are converted to valid indices by
Colormap.__call__()
. If clip == True, out-of-range values are mapped to 0 if low and ncolors-1 if high.-
inverse(value)
-
class matplotlib.colors.ColorConverter
-
Bases:
object
Provides methods for converting color specifications to RGB or RGBA
Caching is used for more efficient conversion upon repeated calls with the same argument.
Ordinarily only the single instance instantiated in this module, colorConverter, is needed.
-
cache = {'#FFC400': (1.0, 0.7686274509803922, 0.0), '.8': (0.8, 0.8, 0.8), '#30a2da': (0.18823529411764706, 0.6352941176470588, 0.8549019607843137), '#6d904f': (0.42745098039215684, 0.5647058823529412, 0.30980392156862746), '0.75': (0.75, 0.75, 0.75), 'g': (0.0, 0.5, 0.0), '#C44E52': (0.7686274509803922, 0.3058823529411765, 0.3215686274509804), '#D0BBFF': (0.8156862745098039, 0.7333333333333333, 1.0), '#E8000B': (0.9098039215686274, 0.0, 0.043137254901960784), '#e5ae38': (0.8980392156862745, 0.6823529411764706, 0.2196078431372549), 'green': (0.0, 0.5019607843137255, 0.0), 'b': (0.0, 0.0, 1.0), '#001C7F': (0.0, 0.10980392156862745, 0.4980392156862745), 'blue': (0.0, 0.0, 1.0), '#bcbcbc': (0.7372549019607844, 0.7372549019607844, 0.7372549019607844), '#D55E00': (0.8352941176470589, 0.3686274509803922, 0.0), '.15': (0.15, 0.15, 0.15), '0.60': (0.6, 0.6, 0.6), 'k': (0.0, 0.0, 0.0), '#8dd3c7': (0.5529411764705883, 0.8274509803921568, 0.7803921568627451), '#97F0AA': (0.592156862745098, 0.9411764705882353, 0.6666666666666666), '#FFB5B8': (1.0, 0.7098039215686275, 0.7215686274509804), '#8EBA42': (0.5568627450980392, 0.7294117647058823, 0.25882352941176473), '#81b1d2': (0.5058823529411764, 0.6941176470588235, 0.8235294117647058), '0.00': (0.0, 0.0, 0.0), '#cbcbcb': (0.796078431372549, 0.796078431372549, 0.796078431372549), '#348ABD': (0.20392156862745098, 0.5411764705882353, 0.7411764705882353), 'yellow': (1.0, 1.0, 0.0), 'm': (0.75, 0, 0.75), '0.70': (0.7, 0.7, 0.7), '#ccebc4': (0.8, 0.9215686274509803, 0.7686274509803922), '#ffed6f': (1.0, 0.9294117647058824, 0.43529411764705883), 'r': (1.0, 0.0, 0.0), '#bfbbd9': (0.7490196078431373, 0.7333333333333333, 0.8509803921568627), '0.50': (0.5, 0.5, 0.5), '#8C0900': (0.5490196078431373, 0.03529411764705882, 0.0), '#0072B2': (0.0, 0.4470588235294118, 0.6980392156862745), '#467821': (0.27450980392156865, 0.47058823529411764, 0.12941176470588237), 'black': (0.0, 0.0, 0.0), '#B0E0E6': (0.6901960784313725, 0.8784313725490196, 0.9019607843137255), '#eeeeee': (0.9333333333333333, 0.9333333333333333, 0.9333333333333333), '#7600A1': (0.4627450980392157, 0.0, 0.6313725490196078), '#8b8b8b': (0.5450980392156862, 0.5450980392156862, 0.5450980392156862), '#006374': (0.0, 0.38823529411764707, 0.4549019607843137), '#f0f0f0': (0.9411764705882353, 0.9411764705882353, 0.9411764705882353), '#fa8174': (0.9803921568627451, 0.5058823529411764, 0.4549019607843137), '#8172B2': (0.5058823529411764, 0.4470588235294118, 0.6980392156862745), '#8A2BE2': (0.5411764705882353, 0.16862745098039217, 0.8862745098039215), 'y': (0.75, 0.75, 0), '#00D7FF': (0.0, 0.8431372549019608, 1.0), 'red': (1.0, 0.0, 0.0), '0.40': (0.4, 0.4, 0.4), '#777777': (0.4666666666666667, 0.4666666666666667, 0.4666666666666667), '#D65F5F': (0.8392156862745098, 0.37254901960784315, 0.37254901960784315), '#afeeee': (0.6862745098039216, 0.9333333333333333, 0.9333333333333333), 'purple': (0.5019607843137255, 0.0, 0.5019607843137255), '#009E73': (0.0, 0.6196078431372549, 0.45098039215686275), '#fdb462': (0.9921568627450981, 0.7058823529411765, 0.3843137254901961), '#B47CC7': (0.7058823529411765, 0.48627450980392156, 0.7803921568627451), '#017517': (0.00392156862745098, 0.4588235294117647, 0.09019607843137255), '#CCB974': (0.8, 0.7254901960784313, 0.4549019607843137), '#56B4E9': (0.33725490196078434, 0.7058823529411765, 0.9137254901960784), '#988ED5': (0.596078431372549, 0.5568627450980392, 0.8352941176470589), '#003FFF': (0.0, 0.24705882352941178, 1.0), '#F0E442': (0.9411764705882353, 0.8941176470588236, 0.25882352941176473), '#EAEAF2': (0.9176470588235294, 0.9176470588235294, 0.9490196078431372), '#bc82bd': (0.7372549019607844, 0.5098039215686274, 0.7411764705882353), '#55A868': (0.3333333333333333, 0.6588235294117647, 0.40784313725490196), '#555555': (0.3333333333333333, 0.3333333333333333, 0.3333333333333333), '#fc4f30': (0.9882352941176471, 0.30980392156862746, 0.18823529411764706), '#92C6FF': (0.5725490196078431, 0.7764705882352941, 1.0), '#00FFCC': (0.0, 1.0, 0.8), 'darkgoldenrod': (0.7215686274509804, 0.5254901960784314, 0.043137254901960784), '#E24A33': (0.8862745098039215, 0.2901960784313726, 0.2), '#A60628': (0.6509803921568628, 0.023529411764705882, 0.1568627450980392), '#FBC15E': (0.984313725490196, 0.7568627450980392, 0.3686274509803922), '#b3de69': (0.7019607843137254, 0.8705882352941177, 0.4117647058823529), '#B8860B': (0.7215686274509804, 0.5254901960784314, 0.043137254901960784), '#6ACC65': (0.41568627450980394, 0.8, 0.396078431372549), '#7A68A6': (0.47843137254901963, 0.40784313725490196, 0.6509803921568628), '#4C72B0': (0.2980392156862745, 0.4470588235294118, 0.6901960784313725), 'c': (0.0, 0.75, 0.75), '#03ED3A': (0.011764705882352941, 0.9294117647058824, 0.22745098039215686), '0.5': (0.5, 0.5, 0.5), 'firebrick': (0.6980392156862745, 0.13333333333333333, 0.13333333333333333), '#EEEEEE': (0.9333333333333333, 0.9333333333333333, 0.9333333333333333), '#E5E5E5': (0.8980392156862745, 0.8980392156862745, 0.8980392156862745), 'white': (1.0, 1.0, 1.0), '#feffb3': (0.996078431372549, 1.0, 0.7019607843137254), '#4878CF': (0.2823529411764706, 0.47058823529411764, 0.8117647058823529), '#64B5CD': (0.39215686274509803, 0.7098039215686275, 0.803921568627451), '#CC79A7': (0.8, 0.4745098039215686, 0.6549019607843137), 'magenta': (1.0, 0.0, 1.0), '#FFFEA3': (1.0, 0.996078431372549, 0.6392156862745098), '#C4AD66': (0.7686274509803922, 0.6784313725490196, 0.4), 'gray': (0.5019607843137255, 0.5019607843137255, 0.5019607843137255), 'w': (1.0, 1.0, 1.0), 'cyan': (0.0, 1.0, 1.0), '#FF9F9A': (1.0, 0.6235294117647059, 0.6039215686274509), '#77BEDB': (0.4666666666666667, 0.7450980392156863, 0.8588235294117647)}
-
colors = {'r': (1.0, 0.0, 0.0), 'w': (1.0, 1.0, 1.0), 'k': (0.0, 0.0, 0.0), 'm': (0.75, 0, 0.75), 'c': (0.0, 0.75, 0.75), 'g': (0.0, 0.5, 0.0), 'y': (0.75, 0.75, 0), 'b': (0.0, 0.0, 1.0)}
-
to_rgb(arg)
-
Returns an RGB tuple of three floats from 0-1.
arg can be an RGB or RGBA sequence or a string in any of several forms:
- a letter from the set ?rgbcmykw?
- a hex color string, like ?#00FFFF?
- a standard name, like ?aqua?
- a string representation of a float, like ?0.4?, indicating gray on a 0-1 scale
if arg is RGBA, the A will simply be discarded.
-
to_rgba(arg, alpha=None)
-
Returns an RGBA tuple of four floats from 0-1.
For acceptable values of arg, see
to_rgb()
. In addition, if arg is ?none? (case-insensitive), then (0,0,0,0) will be returned. If arg is an RGBA sequence and alpha is not None, alpha will replace the original A.
-
to_rgba_array(c, alpha=None)
-
Returns a numpy array of RGBA tuples.
Accepts a single mpl color spec or a sequence of specs.
Special case to handle ?no color?: if c is ?none? (case-insensitive), then an empty array will be returned. Same for an empty list.
-
-
class matplotlib.colors.Colormap(name, N=256)
-
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
. It is worth noting thatmatplotlib.cm.ScalarMappable
subclasses make heavy use of thisdata->normalize->map-to-color
processing chain.Parameters: name : str
The name of the colormap.
N : int
The number of rgb quantization levels.
-
colorbar_extend = None
-
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.
-
is_gray()
-
set_bad(color='k', alpha=None)
-
Set color to be used for masked values.
-
set_over(color='k', alpha=None)
-
Set color to be used for high out-of-range values. Requires norm.clip = False
-
set_under(color='k', alpha=None)
-
Set color to be used for low out-of-range values. Requires norm.clip = False
-
-
class matplotlib.colors.LightSource(azdeg=315, altdeg=45, hsv_min_val=0, hsv_max_val=1, hsv_min_sat=1, hsv_max_sat=0)
-
Bases:
object
Create a light source coming from the specified azimuth and elevation. Angles are in degrees, with the azimuth measured clockwise from north and elevation up from the zero plane of the surface.
The
shade()
is used to produce ?shaded? rgb values for a data array.shade_rgb()
can be used to combine an rgb image with Theshade_rgb()
Thehillshade()
produces an illumination map of a surface.Specify the azimuth (measured clockwise from south) and altitude (measured up from the plane of the surface) of the light source in degrees.
Parameters: azdeg : number, optional
The azimuth (0-360, degrees clockwise from North) of the light source. Defaults to 315 degrees (from the northwest).
altdeg : number, optional
The altitude (0-90, degrees up from horizontal) of the light source. Defaults to 45 degrees from horizontal.
Notes
For backwards compatibility, the parameters hsv_min_val, hsv_max_val, hsv_min_sat, and hsv_max_sat may be supplied at initialization as well. However, these parameters will only be used if ?blend_mode=?hsv?? is passed into
shade()
orshade_rgb()
. See the documentation forblend_hsv()
for more details.-
blend_hsv(rgb, intensity, hsv_max_sat=None, hsv_max_val=None, hsv_min_val=None, hsv_min_sat=None)
-
Take the input data array, convert to HSV values in the given colormap, then adjust those color values to give the impression of a shaded relief map with a specified light source. RGBA values are returned, which can then be used to plot the shaded image with imshow.
The color of the resulting image will be darkened by moving the (s,v) values (in hsv colorspace) toward (hsv_min_sat, hsv_min_val) in the shaded regions, or lightened by sliding (s,v) toward (hsv_max_sat hsv_max_val) in regions that are illuminated. The default extremes are chose so that completely shaded points are nearly black (s = 1, v = 0) and completely illuminated points are nearly white (s = 0, v = 1).
Parameters: rgb : ndarray
An MxNx3 RGB array of floats ranging from 0 to 1 (color image).
intensity : ndarray
An MxNx1 array of floats ranging from 0 to 1 (grayscale image).
hsv_max_sat : number, optional
The maximum saturation value that the intensity map can shift the output image to. Defaults to 1.
hsv_min_sat : number, optional
The minimum saturation value that the intensity map can shift the output image to. Defaults to 0.
hsv_max_val : number, optional
The maximum value (?v? in ?hsv?) that the intensity map can shift the output image to. Defaults to 1.
hsv_min_val: number, optional
The minimum value (?v? in ?hsv?) that the intensity map can shift the output image to. Defaults to 0.
Returns: rgb : ndarray
An MxNx3 RGB array representing the combined images.
-
blend_overlay(rgb, intensity)
-
Combines an rgb image with an intensity map using ?overlay? blending.
Parameters: rgb : ndarray
An MxNx3 RGB array of floats ranging from 0 to 1 (color image).
intensity : ndarray
An MxNx1 array of floats ranging from 0 to 1 (grayscale image).
Returns: rgb : ndarray
An MxNx3 RGB array representing the combined images.
-
blend_soft_light(rgb, intensity)
-
Combines an rgb image with an intensity map using ?soft light? blending. Uses the ?pegtop? formula.
Parameters: rgb : ndarray
An MxNx3 RGB array of floats ranging from 0 to 1 (color image).
intensity : ndarray
An MxNx1 array of floats ranging from 0 to 1 (grayscale image).
Returns: rgb : ndarray
An MxNx3 RGB array representing the combined images.
-
hillshade(elevation, vert_exag=1, dx=1, dy=1, fraction=1.0)
-
Calculates the illumination intensity for a surface using the defined azimuth and elevation for the light source.
Imagine an artificial sun placed at infinity in some azimuth and elevation position illuminating our surface. The parts of the surface that slope toward the sun should brighten while those sides facing away should become darker.
Parameters: elevation : array-like
A 2d array (or equivalent) of the height values used to generate an illumination map
vert_exag : number, optional
The amount to exaggerate the elevation values by when calculating illumination. This can be used either to correct for differences in units between the x-y coordinate system and the elevation coordinate system (e.g. decimal degrees vs meters) or to exaggerate or de-emphasize topographic effects.
dx : number, optional
The x-spacing (columns) of the input elevation grid.
dy : number, optional
The y-spacing (rows) of the input elevation grid.
fraction : number, optional
Increases or decreases the contrast of the hillshade. Values greater than one will cause intermediate values to move closer to full illumination or shadow (and clipping any values that move beyond 0 or 1). Note that this is not visually or mathematically the same as vertical exaggeration.
Returns
??-
intensity : ndarray
A 2d array of illumination values between 0-1, where 0 is completely in shadow and 1 is completely illuminated.
-
shade(data, cmap, norm=None, blend_mode='hsv', vmin=None, vmax=None, vert_exag=1, dx=1, dy=1, fraction=1, **kwargs)
-
Combine colormapped data values with an illumination intensity map (a.k.a. ?hillshade?) of the values.
Parameters: data : array-like
A 2d array (or equivalent) of the height values used to generate a shaded map.
cmap :
Colormap
instanceThe colormap used to color the data array. Note that this must be a
Colormap
instance. For example, rather than passing incmap='gist_earth'
, usecmap=plt.get_cmap('gist_earth')
instead.norm :
Normalize
instance, optionalThe normalization used to scale values before colormapping. If None, the input will be linearly scaled between its min and max.
blend_mode : {?hsv?, ?overlay?, ?soft?} or callable, optional
The type of blending used to combine the colormapped data values with the illumination intensity. For backwards compatibility, this defaults to ?hsv?. Note that for most topographic surfaces, ?overlay? or ?soft? appear more visually realistic. If a user-defined function is supplied, it is expected to combine an MxNx3 RGB array of floats (ranging 0 to 1) with an MxNx1 hillshade array (also 0 to 1). (Call signature
func(rgb, illum, **kwargs)
) Additional kwargs supplied to this function will be passed on to the blend_mode function.vmin : scalar or None, optional
The minimum value used in colormapping data. If None the minimum value in data is used. If norm is specified, then this argument will be ignored.
vmax : scalar or None, optional
The maximum value used in colormapping data. If None the maximum value in data is used. If norm is specified, then this argument will be ignored.
vert_exag : number, optional
The amount to exaggerate the elevation values by when calculating illumination. This can be used either to correct for differences in units between the x-y coordinate system and the elevation coordinate system (e.g. decimal degrees vs meters) or to exaggerate or de-emphasize topography.
dx : number, optional
The x-spacing (columns) of the input elevation grid.
dy : number, optional
The y-spacing (rows) of the input elevation grid.
fraction : number, optional
Increases or decreases the contrast of the hillshade. Values greater than one will cause intermediate values to move closer to full illumination or shadow (and clipping any values that move beyond 0 or 1). Note that this is not visually or mathematically the same as vertical exaggeration.
Additional kwargs are passed on to the *blend_mode* function.
Returns: rgba : ndarray
An MxNx4 array of floats ranging between 0-1.
-
shade_rgb(rgb, elevation, fraction=1.0, blend_mode='hsv', vert_exag=1, dx=1, dy=1, **kwargs)
-
Take the input RGB array (ny*nx*3) adjust their color values to given the impression of a shaded relief map with a specified light source using the elevation (ny*nx). A new RGB array ((ny*nx*3)) is returned.
Parameters: rgb : array-like
An MxNx3 RGB array, assumed to be in the range of 0 to 1.
elevation : array-like
A 2d array (or equivalent) of the height values used to generate a shaded map.
fraction : number
Increases or decreases the contrast of the hillshade. Values greater than one will cause intermediate values to move closer to full illumination or shadow (and clipping any values that move beyond 0 or 1). Note that this is not visually or mathematically the same as vertical exaggeration.
blend_mode : {?hsv?, ?overlay?, ?soft?} or callable, optional
The type of blending used to combine the colormapped data values with the illumination intensity. For backwards compatibility, this defaults to ?hsv?. Note that for most topographic surfaces, ?overlay? or ?soft? appear more visually realistic. If a user-defined function is supplied, it is expected to combine an MxNx3 RGB array of floats (ranging 0 to 1) with an MxNx1 hillshade array (also 0 to 1). (Call signature
func(rgb, illum, **kwargs)
) Additional kwargs supplied to this function will be passed on to the blend_mode function.vert_exag : number, optional
The amount to exaggerate the elevation values by when calculating illumination. This can be used either to correct for differences in units between the x-y coordinate system and the elevation coordinate system (e.g. decimal degrees vs meters) or to exaggerate or de-emphasize topography.
dx : number, optional
The x-spacing (columns) of the input elevation grid.
dy : number, optional
The y-spacing (rows) of the input elevation grid.
Additional kwargs are passed on to the *blend_mode* function.
Returns: shaded_rgb : ndarray
An MxNx3 array of floats ranging between 0-1.
-
-
class matplotlib.colors.LinearSegmentedColormap(name, segmentdata, N=256, gamma=1.0)
-
Bases:
matplotlib.colors.Colormap
Colormap objects based on lookup tables using linear segments.
The lookup table is generated using linear interpolation for each primary color, with the 0-1 domain divided into any number of segments.
Create color map from linear mapping segments
segmentdata argument is a dictionary with a red, green and blue entries. Each entry should be a list of x, y0, y1 tuples, forming rows in a table. Entries for alpha are optional.
Example: suppose you want red to increase from 0 to 1 over the bottom half, green to do the same over the middle half, and blue over the top half. Then you would use:
cdict = {'red': [(0.0, 0.0, 0.0), (0.5, 1.0, 1.0), (1.0, 1.0, 1.0)], 'green': [(0.0, 0.0, 0.0), (0.25, 0.0, 0.0), (0.75, 1.0, 1.0), (1.0, 1.0, 1.0)], 'blue': [(0.0, 0.0, 0.0), (0.5, 0.0, 0.0), (1.0, 1.0, 1.0)]}
Each row in the table for a given color is a sequence of x, y0, y1 tuples. In each sequence, x must increase monotonically from 0 to 1. For any input value z falling between x[i] and x[i+1], the output value of a given color will be linearly interpolated between y1[i] and y0[i+1]:
row i: x y0 y1 / / row i+1: x y0 y1
Hence y0 in the first row and y1 in the last row are never used.
See also
LinearSegmentedColormap.from_list()
Static method; factory function for generating a smoothly-varying LinearSegmentedColormap.makeMappingArray()
For information about making a mapping array.-
static from_list(name, colors, N=256, gamma=1.0)
-
Make a linear segmented colormap with name from a sequence of colors which evenly transitions from colors[0] at val=0 to colors[-1] at val=1. N is the number of rgb quantization levels. Alternatively, a list of (value, color) tuples can be given to divide the range unevenly.
-
set_gamma(gamma)
-
Set a new gamma value and regenerate color map.
-
-
class matplotlib.colors.ListedColormap(colors, name='from_list', N=None)
-
Bases:
matplotlib.colors.Colormap
Colormap object generated from a list of colors.
This may be most useful when indexing directly into a colormap, but it can also be used to generate special colormaps for ordinary mapping.
Make a colormap from a list of colors.
- colors
- a list of matplotlib color specifications, or an equivalent Nx3 or Nx4 floating point array (N rgb or rgba values)
- name
- a string to identify the colormap
- N
-
the number of entries in the map. The default is None, in which case there is one colormap entry for each element in the list of colors. If:
N < len(colors)
the list will be truncated at N. If:
N > len(colors)
the list will be extended by repetition.
-
class matplotlib.colors.LogNorm(vmin=None, vmax=None, clip=False)
-
Bases:
matplotlib.colors.Normalize
Normalize a given value to the 0-1 range on a log scale
If vmin or vmax is not given, they are initialized from the minimum and maximum value respectively of the first input processed. That is, __call__(A) calls autoscale_None(A). If clip is True and the given value falls outside the range, the returned value will be 0 or 1, whichever is closer. Returns 0 if:
vmin==vmax
Works with scalars or arrays, including masked arrays. If clip is True, masked values are set to 1; otherwise they remain masked. Clipping silently defeats the purpose of setting the over, under, and masked colors in the colormap, so it is likely to lead to surprises; therefore the default is clip = False.
-
autoscale(A)
-
Set vmin, vmax to min, max of A.
-
autoscale_None(A)
-
autoscale only None-valued vmin or vmax
-
inverse(value)
-
-
class matplotlib.colors.NoNorm(vmin=None, vmax=None, clip=False)
-
Bases:
matplotlib.colors.Normalize
Dummy replacement for Normalize, for the case where we want to use indices directly in a
ScalarMappable
.If vmin or vmax is not given, they are initialized from the minimum and maximum value respectively of the first input processed. That is, __call__(A) calls autoscale_None(A). If clip is True and the given value falls outside the range, the returned value will be 0 or 1, whichever is closer. Returns 0 if:
vmin==vmax
Works with scalars or arrays, including masked arrays. If clip is True, masked values are set to 1; otherwise they remain masked. Clipping silently defeats the purpose of setting the over, under, and masked colors in the colormap, so it is likely to lead to surprises; therefore the default is clip = False.
-
inverse(value)
-
-
class matplotlib.colors.Normalize(vmin=None, vmax=None, clip=False)
-
Bases:
object
A class which, when called, can normalize data into the
[0.0, 1.0]
interval.If vmin or vmax is not given, they are initialized from the minimum and maximum value respectively of the first input processed. That is, __call__(A) calls autoscale_None(A). If clip is True and the given value falls outside the range, the returned value will be 0 or 1, whichever is closer. Returns 0 if:
vmin==vmax
Works with scalars or arrays, including masked arrays. If clip is True, masked values are set to 1; otherwise they remain masked. Clipping silently defeats the purpose of setting the over, under, and masked colors in the colormap, so it is likely to lead to surprises; therefore the default is clip = False.
-
autoscale(A)
-
Set vmin, vmax to min, max of A.
-
autoscale_None(A)
-
autoscale only None-valued vmin or vmax
-
inverse(value)
-
static process_value(value)
-
Homogenize the input value for easy and efficient normalization.
value can be a scalar or sequence.
Returns result, is_scalar, where result is a masked array matching value. Float dtypes are preserved; integer types with two bytes or smaller are converted to np.float32, and larger types are converted to np.float. Preserving float32 when possible, and using in-place operations, can greatly improve speed for large arrays.
Experimental; we may want to add an option to force the use of float32.
-
scaled()
-
return true if vmin and vmax set
-
-
class matplotlib.colors.PowerNorm(gamma, vmin=None, vmax=None, clip=False)
-
Bases:
matplotlib.colors.Normalize
Normalize a given value to the
[0, 1]
interval with a power-law scaling. This will clip any negative data points to 0.-
autoscale(A)
-
Set vmin, vmax to min, max of A.
-
autoscale_None(A)
-
autoscale only None-valued vmin or vmax
-
inverse(value)
-
-
class matplotlib.colors.SymLogNorm(linthresh, linscale=1.0, vmin=None, vmax=None, clip=False)
-
Bases:
matplotlib.colors.Normalize
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).
linthresh: The range within which the plot is linear (to avoid having the plot go to infinity around zero).
linscale: This allows the linear range (-linthresh to 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. Defaults to 1.
-
autoscale(A)
-
Set vmin, vmax to min, max of A.
-
autoscale_None(A)
-
autoscale only None-valued vmin or vmax
-
inverse(value)
-
-
matplotlib.colors.from_levels_and_colors(levels, colors, extend='neither')
-
A helper routine to generate a cmap and a norm instance which behave similar to contourf?s levels and colors arguments.
Parameters: levels : sequence of numbers
The quantization levels used to construct the
BoundaryNorm
. Valuesv
are quantizized to leveli
iflev[i] <= v < lev[i+1]
.colors : sequence of colors
The fill color to use for each level. If
extend
is ?neither? there must ben_level - 1
colors. For anextend
of ?min? or ?max? add one extra color, and for anextend
of ?both? add two colors.extend : {?neither?, ?min?, ?max?, ?both?}, optional
The behaviour when a value falls out of range of the given levels. See
contourf()
for details.Returns: (cmap, norm) : tuple containing a
Colormap
and aNormalize
instance
-
matplotlib.colors.hex2color(s)
-
Take a hex string s and return the corresponding rgb 3-tuple Example: #efefef -> (0.93725, 0.93725, 0.93725)
-
matplotlib.colors.hsv_to_rgb(hsv)
-
convert hsv values in a numpy array to rgb values all values assumed to be in range [0, 1]
Parameters: hsv : (..., 3) array-like
All values assumed to be in range [0, 1]
Returns: rgb : (..., 3) ndarray
Colors converted to RGB values in range [0, 1]
-
matplotlib.colors.is_color_like(c)
-
Return True if c can be converted to RGB
-
matplotlib.colors.makeMappingArray(N, data, gamma=1.0)
-
Create an N -element 1-d lookup table
data represented by a list of x,y0,y1 mapping correspondences. Each element in this list represents how a value between 0 and 1 (inclusive) represented by x is mapped to a corresponding value between 0 and 1 (inclusive). The two values of y are to allow for discontinuous mapping functions (say as might be found in a sawtooth) where y0 represents the value of y for values of x <= to that given, and y1 is the value to be used for x > than that given). The list must start with x=0, end with x=1, and all values of x must be in increasing order. Values between the given mapping points are determined by simple linear interpolation.
Alternatively, data can be a function mapping values between 0 - 1 to 0 - 1.
The function returns an array ?result? where
result[x*(N-1)]
gives the closest value for values of x between 0 and 1.
-
matplotlib.colors.rgb2hex(rgb)
-
Given an rgb or rgba sequence of 0-1 floats, return the hex string
-
matplotlib.colors.rgb_to_hsv(arr)
-
convert float rgb values (in the range [0, 1]), in a numpy array to hsv values.
Parameters: arr : (..., 3) array-like
All values must be in the range [0, 1]
Returns: hsv : (..., 3) ndarray
Colors converted to hsv values in range [0, 1]
Please login to continue.