MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / LinearSegmentedColormap

Class LinearSegmentedColormap

lib/matplotlib/colors.py:1079–1288  ·  view source on GitHub ↗

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.

Source from the content-addressed store, hash-verified

1077
1078
1079class LinearSegmentedColormap(Colormap):
1080 """
1081 Colormap objects based on lookup tables using linear segments.
1082
1083 The lookup table is generated using linear interpolation for each
1084 primary color, with the 0-1 domain divided into any number of
1085 segments.
1086 """
1087
1088 def __init__(self, name, segmentdata, N=256, gamma=1.0, *,
1089 bad=None, under=None, over=None):
1090 """
1091 Create colormap from linear mapping segments.
1092
1093 Parameters
1094 ----------
1095 name : str
1096 The name of the colormap.
1097 segmentdata : dict
1098 A dictionary with keys "red", "green", "blue" for the color channels.
1099 Each entry should be a list of *x*, *y0*, *y1* tuples, forming rows
1100 in a table. Entries for alpha are optional.
1101
1102 Example: suppose you want red to increase from 0 to 1 over
1103 the bottom half, green to do the same over the middle half,
1104 and blue over the top half. Then you would use::
1105
1106 {
1107 'red': [(0.0, 0.0, 0.0),
1108 (0.5, 1.0, 1.0),
1109 (1.0, 1.0, 1.0)],
1110 'green': [(0.0, 0.0, 0.0),
1111 (0.25, 0.0, 0.0),
1112 (0.75, 1.0, 1.0),
1113 (1.0, 1.0, 1.0)],
1114 'blue': [(0.0, 0.0, 0.0),
1115 (0.5, 0.0, 0.0),
1116 (1.0, 1.0, 1.0)]
1117 }
1118
1119 Each row in the table for a given color is a sequence of
1120 *x*, *y0*, *y1* tuples. In each sequence, *x* must increase
1121 monotonically from 0 to 1. For any input value *z* falling
1122 between *x[i]* and *x[i+1]*, the output value of a given color
1123 will be linearly interpolated between *y1[i]* and *y0[i+1]*::
1124
1125 row i: x y0 y1
1126 /
1127 /
1128 row i+1: x y0 y1
1129
1130 Hence, y0 in the first row and y1 in the last row are never used.
1131
1132 N : int
1133 The number of RGB quantization levels.
1134 gamma : float
1135 Gamma correction factor for input distribution x of the mapping.
1136 See also https://en.wikipedia.org/wiki/Gamma_correction.

Callers 5

plot_linearmapFunction · 0.90
custom_cmap.pyFile · 0.90
from_listMethod · 0.85
resampledMethod · 0.85
reversedMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…