matplotlib.colors.LinearSegmentedColormap#

classmatplotlib.colors.LinearSegmentedColormap(name,segmentdata,N=256,gamma=1.0)[source]#

Bases:Colormap

Colormap objects based on lookup tables using linear segments.

The lookup table is generated using linear interpolation for eachprimary color, with the 0-1 domain divided into any number ofsegments.

Create colormap from linear mapping segments

segmentdata argument is a dictionary with a red, green and blueentries. Each entry should be a list ofx,y0,y1 tuples,forming rows in a table. Entries for alpha are optional.

Example: suppose you want red to increase from 0 to 1 overthe 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 ofx,y0,y1 tuples. In each sequence,x must increasemonotonically from 0 to 1. For any input valuez fallingbetweenx[i] andx[i+1], the output value of a given colorwill be linearly interpolated betweeny1[i] andy0[i+1]:

rowi:xy0y1//rowi+1:xy0y1

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.

staticfrom_list(name,colors,N=256,gamma=1.0)[source]#

Create aLinearSegmentedColormap from a list of colors.

Parameters:
namestr

The name of the colormap.

colorslist ofcolor or list of (value, color)

If only colors are given, they are equidistantly mapped from therange\([0, 1]\); i.e. 0 maps tocolors[0] and 1 maps tocolors[-1].If (value, color) pairs are given, the mapping is fromvaluetocolor. This can be used to divide the range unevenly.

Nint

The number of RGB quantization levels.

gammafloat
resampled(lutsize)[source]#

Return a new colormap withlutsize entries.

reversed(name=None)[source]#

Return a reversed instance of the Colormap.

Parameters:
namestr, optional

The name for the reversed colormap. If None, thename is set toself.name+"_r".

Returns:
LinearSegmentedColormap

The reversed colormap.

set_gamma(gamma)[source]#

Set a new gamma value and regenerate colormap.

Examples usingmatplotlib.colors.LinearSegmentedColormap#

Demo CurveLinear Grid2

Demo CurveLinear Grid2

Create a colormap from a list of colors

Create a colormap from a list of colors

Contour Demo

Contour Demo

Contour image

Contour image

Contourf demo

Contourf demo

Contourf and log color scale

Contourf and log color scale

Image resampling

Image resampling

Many ways to plot images

Many ways to plot images

Image with masked values

Image with masked values

Image nonuniform

Image nonuniform

Layer images with alpha blending

Layer images with alpha blending

pcolormesh

pcolormesh

Shading example

Shading example

Bar chart with gradients

Bar chart with gradients

Manual Contour

Manual Contour

AGG filter

AGG filter

Matplotlib logo

Matplotlib logo

Table Demo

Table Demo

Plot contour (level) curves in 3D

Plot contour (level) curves in 3D

Plot contour (level) curves in 3D using the extend3d option

Plot contour (level) curves in 3D using the extend3d option

Filled contours

Filled contours

Custom hillshading in a 3D surface plot

Custom hillshading in a 3D surface plot

3D plots as subplots

3D plots as subplots

3D surface (colormap)

3D surface (colormap)

3D surface with polar coordinates

3D surface with polar coordinates

Triangular 3D contour plot

Triangular 3D contour plot

Triangular 3D filled contour plot

Triangular 3D filled contour plot

More triangular 3D surfaces

More triangular 3D surfaces

Dolphins

Dolphins

Shaded & power normalized rendering

Shaded & power normalized rendering

Hillshading

Hillshading

Left ventricle bullseye

Left ventricle bullseye

Topographic hillshading

Topographic hillshading

Axes box aspect

Axes box aspect

Compose custom legends

Compose custom legends

Using a text as a Path

Using a text as a Path

plot_surface(X, Y, Z)

plot_surface(X, Y, Z)

plot_trisurf(x, y, z)

plot_trisurf(x, y, z)

Customized Colorbars Tutorial

Customized Colorbars Tutorial

Creating Colormaps in Matplotlib

Creating Colormaps in Matplotlib

Colormap normalization

Colormap normalization