-
Notifications
You must be signed in to change notification settings - Fork 0
/
cbf_colors.py
140 lines (133 loc) · 4.74 KB
/
cbf_colors.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
from matplotlib import colors as mcolors
def rgb_to_fractionrgb(vals):
"""Converts RGB values to fractions for matplotlib.
Assumes normalization to 255"""
currfrac = []
for i in vals:
if i > 255:
raise ValueError("RGB value can't be > 255")
currfrac.append(i/255.)
return tuple(currfrac)
# Colorblind friendly 8-colors from https://jfly.uni-koeln.de/color/#pallet
# Values are in RGB fractions
cnames = [ 'cbf_key', \
'cbf_orange', \
# NOTE difference to cbf_skyblue in 12-color!
'cbf_sky_blue', \
'cbf_bluish_green', \
'cbf_yellow', \
'cbf_blue', \
'cbf_vermillion', \
'cbf_reddish_purple' ]
cvals = [ (0.0, 0.0, 0.0), \
(0.9, 0.6, 0.0), \
(0.35, 0.7, 0.9), \
(0.0, 0.6, 0.5), \
(0.95, 0.9, 0.25), \
(0.0, 0.45, 0.7), \
(0.8, 0.4, 0.0), \
(0.8, 0.6, 0.7) ]
chexes = list(map(mcolors.to_hex, cvals))
mcolors.get_named_colors_mapping().update(zip(cnames, chexes))
# Colorblind friendly 12-colors from http://mkweb.bcgsc.ca/colorblind/
# Values are in RGB values
cnames = [ 'cbf_dark_teal', \
'cbf_purple', \
'cbf_softblue', \
# NOTE difference to cbf_sky_blue in 8-color!
'cbf_skyblue', \
'cbf_violet', \
'cbf_cyan', \
'cbf_redrusset', \
'cbf_peach', \
'cbf_green', \
'cbf_lime', \
'cbf_peagreen', \
'cbf_wheat' ]
cvals = [ (1, 110, 130), \
(125, 45, 145), \
(47, 94, 171), \
(68, 152, 211), \
(205, 133, 185), \
(70, 195, 208), \
(170, 29, 63), \
(244, 119, 82), \
(25, 179, 90), \
(237, 232, 59), \
(171, 211, 122), \
(249, 229, 190) ]
cval_fracs = list(map(rgb_to_fractionrgb, cvals))
chexes = list(map(mcolors.to_hex, cval_fracs))
mcolors.get_named_colors_mapping().update(zip(cnames, chexes))
# If the YlOrBr Brewer colormap already available in matplotlib
# isn't suitable, it can be recreated with the following 9 colors from http://mkweb.bcgsc.ca/brewer/
# Values are in RGB values
cnames = [ 'cbf_ylorbr-9-seq-1', \
'cbf_ylorbr-9-seq-2', \
'cbf_ylorbr-9-seq-3', \
'cbf_ylorbr-9-seq-4', \
'cbf_ylorbr-9-seq-5', \
'cbf_ylorbr-9-seq-6', \
'cbf_ylorbr-9-seq-7', \
'cbf_ylorbr-9-seq-8', \
'cbf_ylorbr-9-seq-9', ]
cvals = [ (255, 255, 229), \
(255, 247, 188), \
(254, 227, 145), \
(254, 196, 79), \
(254, 153, 41), \
(236, 112, 20), \
(204, 76, 2), \
(153, 52, 4), \
(102, 37, 6) ]
cval_fracs = list(map(rgb_to_fractionrgb, cvals))
chexes = list(map(mcolors.to_hex, cval_fracs))
mcolors.get_named_colors_mapping().update(zip(cnames, chexes))
# If the RdYlBu Brewer colormap already available in matplotlib
# isn't suitable, it can be recreated with the following 9 colors from http://mkweb.bcgsc.ca/brewer/
# Values are in RGB values
cnames = [ 'cbf_rdylbu-9-seq-1', \
'cbf_rdylbu-9-seq-2', \
'cbf_rdylbu-9-seq-3', \
'cbf_rdylbu-9-seq-4', \
'cbf_rdylbu-9-seq-5', \
'cbf_rdylbu-9-seq-6', \
'cbf_rdylbu-9-seq-7', \
'cbf_rdylbu-9-seq-8', \
'cbf_rdylbu-9-seq-9', ]
cvals = [ (215, 48, 39), \
(244, 109, 67), \
(253, 174, 39), \
(254, 224, 144), \
(255, 255, 191), \
(224, 243, 248), \
(171, 217, 233), \
(116, 173, 209), \
(69, 117, 180) ]
cval_fracs = list(map(rgb_to_fractionrgb, cvals))
chexes = list(map(mcolors.to_hex, cval_fracs))
mcolors.get_named_colors_mapping().update(zip(cnames, chexes))
# If the PiYG Brewer colormap already available in matplotlib
# isn't suitable, it can be recreated with the following 9 colors from http://mkweb.bcgsc.ca/brewer/
# Values are in RGB values
cnames = [ 'cbf_piyg-9-seq-1', \
'cbf_piyg-9-seq-2', \
'cbf_piyg-9-seq-3', \
'cbf_piyg-9-seq-4', \
'cbf_piyg-9-seq-5', \
'cbf_piyg-9-seq-6', \
'cbf_piyg-9-seq-7', \
'cbf_piyg-9-seq-8', \
'cbf_piyg-9-seq-9', ]
cvals = [ (197, 27, 125), \
(222, 119, 174), \
(241, 182, 218), \
(253, 224, 239), \
(247, 247, 247), \
(230, 245, 208), \
(184, 225, 134), \
(127, 188, 65), \
(77, 146, 33) ]
cval_fracs = list(map(rgb_to_fractionrgb, cvals))
chexes = list(map(mcolors.to_hex, cval_fracs))
mcolors.get_named_colors_mapping().update(zip(cnames, chexes))