3import matplotlib.pyplot
as plt
4from mpl_toolkits.axes_grid1
import AxesGrid
9 m = (center-clim[0])/(clim[1]-clim[0])
10 start = 0.0 + shrink/2.
11 stop = 1.0 - shrink/2.
20 Function to offset the "center" of a colormap. Useful
for
21 data
with a negative min
and positive max
and you want the
22 middle of the colormap
's dynamic range to be at zero
26 cmap : The matplotlib colormap to be altered
27 start : Offset from lowest point
in the colormap
's range.
28 Defaults to 0.0 (no lower ofset). Should be between
30 midpoint : The new center of the colormap. Defaults to
31 0.5 (no shift). Should be between 0.0
and 1.0. In
32 general, this should be 1 - vmax/(vmax +
abs(vmin))
33 For example
if your data range
from -15.0 to +5.0
and
34 you want the center of the colormap at 0.0, `midpoint`
35 should be set to 1 - 5/(5 + 15))
or 0.75
36 stop : Offset
from highets point
in the colormap
's range.
37 Defaults to 1.0 (no upper ofset). Should be between
48 reg_index = np.linspace(start, stop, 257)
51 shift_index = np.hstack([
52 np.linspace(0.0, midpoint, 128, endpoint=
False),
53 np.linspace(midpoint, 1.0, 129, endpoint=
True)
56 for ri, si
in zip(reg_index, shift_index):
59 cdict[
'red'].
append((si, r, r))
60 cdict[
'green'].
append((si, g, g))
61 cdict[
'blue'].
append((si, b, b))
62 cdict[
'alpha'].
append((si, a, a))
64 newcmap = matplotlib.colors.LinearSegmentedColormap(name, cdict)
65 plt.register_cmap(cmap=newcmap)
subroutine append(buffer, i, d)
def centercmap(cmap, clim, center=0., shrink=0.)
def shiftedColorMap(cmap, start=0, midpoint=0.5, stop=1.0, name='shiftedcmap')