Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b0dcaa0

Browse files
committed
Merge pull request #468 from pschella/cubehelix
Added cubehelix monotonically increasing colorscheme (developed by D.A. G
2 parents 801d2ab + 87321b7 commit b0dcaa0

2 files changed

Lines changed: 64 additions & 0 deletions

File tree

lib/matplotlib/_cm.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,68 @@
4646
'blue': lambda x: -1.1 * np.sin((x * 20.9) * np.pi),
4747
}
4848

49+
def cubehelix(gamma=1.0, s=0.5, r=-1.5, h=1.0):
50+
"""Return custom data dictionary of (r,g,b) conversion functions, which
51+
can be used with :func:`register_cmap`, for the cubehelix color scheme.
52+
53+
Unlike most other color schemes cubehelix was designed by D.A. Green to
54+
be monotonically increasing in terms of perceived brightness.
55+
Also, when printed on a black and white postscript printer, the scheme
56+
results in a greyscale with monotonically increasing brightness.
57+
This color scheme is named cubehelix because the r,g,b values produced
58+
can be visualised as a squashed helix around the diagonal in the
59+
r,g,b color cube.
60+
61+
For a unit color cube (i.e. 3-D coordinates for r,g,b each in the
62+
range 0 to 1) the color scheme starts at (r,g,b) = (0,0,0), i.e. black,
63+
and finishes at (r,g,b) = (1,1,1), i.e. white. For some fraction *x*,
64+
between 0 and 1, the color is the corresponding grey value at that
65+
fraction along the black to white diagonal (x,x,x) plus a color
66+
element. This color element is calculated in a plane of constant
67+
perceived intensity and controlled by the following parameters.
68+
69+
Optional keyword arguments:
70+
71+
========= =======================================================
72+
Keyword Description
73+
========= =======================================================
74+
gamma gamma factor to emphasise either low intensity values
75+
(gamma < 1), or high intensity values (gamma > 1);
76+
defaults to 1.0.
77+
s the start color; defaults to 0.5 (i.e. purple).
78+
r the number of r,g,b rotations in color that are made
79+
from the start to the end of the color scheme; defaults
80+
to -1.5 (i.e. -> B -> G -> R -> B).
81+
h the hue parameter which controls how saturated the
82+
colors are. If this parameter is zero then the color
83+
scheme is purely a greyscale; defaults to 1.0.
84+
========= =======================================================
85+
86+
"""
87+
88+
def get_color_function(p0, p1):
89+
def color(x):
90+
# Apply gamma factor to emphasise low or high intensity values
91+
xg = x**gamma
92+
93+
# Calculate amplitude and angle of deviation from the black
94+
# to white diagonal in the plane of constant
95+
# perceived intensity.
96+
a = h * xg * (1 - xg) / 2
97+
98+
phi = 2 * np.pi * (s / 3 + r * x)
99+
100+
return xg + a * (p0 * np.cos(phi) + p1 * np.sin(phi))
101+
return color
102+
103+
return {
104+
'red': get_color_function(-0.14861, 1.78277),
105+
'green': get_color_function(-0.29227, -0.90649),
106+
'blue': get_color_function(1.97294, 0.0),
107+
}
108+
109+
_cubehelix_data = cubehelix()
110+
49111
_bwr_data = ((0.0, 0.0, 1.0), (1.0, 1.0, 1.0), (1.0, 0.0, 0.0))
50112
_brg_data = ((0.0, 0.0, 1.0), (1.0, 0.0, 0.0), (0.0, 1.0, 0.0))
51113

@@ -1575,6 +1637,7 @@ def gfunc32(x):
15751637
'brg': _brg_data,
15761638
'cool': _cool_data,
15771639
'copper': _copper_data,
1640+
'cubehelix': _cubehelix_data,
15781641
'flag': _flag_data,
15791642
'gnuplot': _gnuplot_data,
15801643
'gnuplot2': _gnuplot2_data,

lib/matplotlib/cm.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import matplotlib.colors as colors
1414
import matplotlib.cbook as cbook
1515
from matplotlib._cm import datad
16+
from matplotlib._cm import cubehelix
1617

1718
cmap_d = dict()
1819

0 commit comments

Comments
 (0)