Skip to content

tol_colors

Definition of colour schemes for lines and maps that also work for colour-blind people. See https://personal.sron.nl/~pault/ for background information and best usage of the schemes.

Copyright (c) 2021, Paul Tol All rights reserved.

License: Standard 3-clause BSD

TOLcmaps

Bases: object

Class TOLcmaps definition.

Source code in pyhdx/tol_colors.py
 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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
class TOLcmaps(object):
    """
    Class TOLcmaps definition.
    """

    def __init__(self):
        """ """
        self.cmap = None
        self.cname = None
        self.namelist = (
            "sunset_discrete",
            "sunset",
            "BuRd_discrete",
            "BuRd",
            "PRGn_discrete",
            "PRGn",
            "YlOrBr_discrete",
            "YlOrBr",
            "WhOrBr",
            "iridescent",
            "rainbow_PuRd",
            "rainbow_PuBr",
            "rainbow_WhRd",
            "rainbow_WhBr",
            "rainbow_discrete",
        )

        self.funcdict = dict(
            zip(
                self.namelist,
                (
                    self.__sunset_discrete,
                    self.__sunset,
                    self.__BuRd_discrete,
                    self.__BuRd,
                    self.__PRGn_discrete,
                    self.__PRGn,
                    self.__YlOrBr_discrete,
                    self.__YlOrBr,
                    self.__WhOrBr,
                    self.__iridescent,
                    self.__rainbow_PuRd,
                    self.__rainbow_PuBr,
                    self.__rainbow_WhRd,
                    self.__rainbow_WhBr,
                    self.__rainbow_discrete,
                ),
            )
        )

    def __sunset_discrete(self):
        """
        Define colormap 'sunset_discrete'.
        """
        clrs = [
            "#364B9A",
            "#4A7BB7",
            "#6EA6CD",
            "#98CAE1",
            "#C2E4EF",
            "#EAECCC",
            "#FEDA8B",
            "#FDB366",
            "#F67E4B",
            "#DD3D2D",
            "#A50026",
        ]
        self.cmap = discretemap(self.cname, clrs)
        self.cmap.set_bad("#FFFFFF")

    def __sunset(self):
        """
        Define colormap 'sunset'.
        """
        clrs = [
            "#364B9A",
            "#4A7BB7",
            "#6EA6CD",
            "#98CAE1",
            "#C2E4EF",
            "#EAECCC",
            "#FEDA8B",
            "#FDB366",
            "#F67E4B",
            "#DD3D2D",
            "#A50026",
        ]
        self.cmap = LinearSegmentedColormap.from_list(self.cname, clrs)
        self.cmap.set_bad("#FFFFFF")

    def __BuRd_discrete(self):
        """
        Define colormap 'BuRd_discrete'.
        """
        clrs = [
            "#2166AC",
            "#4393C3",
            "#92C5DE",
            "#D1E5F0",
            "#F7F7F7",
            "#FDDBC7",
            "#F4A582",
            "#D6604D",
            "#B2182B",
        ]
        self.cmap = discretemap(self.cname, clrs)
        self.cmap.set_bad("#FFEE99")

    def __BuRd(self):
        """
        Define colormap 'BuRd'.
        """
        clrs = [
            "#2166AC",
            "#4393C3",
            "#92C5DE",
            "#D1E5F0",
            "#F7F7F7",
            "#FDDBC7",
            "#F4A582",
            "#D6604D",
            "#B2182B",
        ]
        self.cmap = LinearSegmentedColormap.from_list(self.cname, clrs)
        self.cmap.set_bad("#FFEE99")

    def __PRGn_discrete(self):
        """
        Define colormap 'PRGn_discrete'.
        """
        clrs = [
            "#762A83",
            "#9970AB",
            "#C2A5CF",
            "#E7D4E8",
            "#F7F7F7",
            "#D9F0D3",
            "#ACD39E",
            "#5AAE61",
            "#1B7837",
        ]
        self.cmap = discretemap(self.cname, clrs)
        self.cmap.set_bad("#FFEE99")

    def __PRGn(self):
        """
        Define colormap 'PRGn'.
        """
        clrs = [
            "#762A83",
            "#9970AB",
            "#C2A5CF",
            "#E7D4E8",
            "#F7F7F7",
            "#D9F0D3",
            "#ACD39E",
            "#5AAE61",
            "#1B7837",
        ]
        self.cmap = LinearSegmentedColormap.from_list(self.cname, clrs)
        self.cmap.set_bad("#FFEE99")

    def __YlOrBr_discrete(self):
        """
        Define colormap 'YlOrBr_discrete'.
        """
        clrs = [
            "#FFFFE5",
            "#FFF7BC",
            "#FEE391",
            "#FEC44F",
            "#FB9A29",
            "#EC7014",
            "#CC4C02",
            "#993404",
            "#662506",
        ]
        self.cmap = discretemap(self.cname, clrs)
        self.cmap.set_bad("#888888")

    def __YlOrBr(self):
        """
        Define colormap 'YlOrBr'.
        """
        clrs = [
            "#FFFFE5",
            "#FFF7BC",
            "#FEE391",
            "#FEC44F",
            "#FB9A29",
            "#EC7014",
            "#CC4C02",
            "#993404",
            "#662506",
        ]
        self.cmap = LinearSegmentedColormap.from_list(self.cname, clrs)
        self.cmap.set_bad("#888888")

    def __WhOrBr(self):
        """
        Define colormap 'WhOrBr'.
        """
        clrs = [
            "#FFFFFF",
            "#FFF7BC",
            "#FEE391",
            "#FEC44F",
            "#FB9A29",
            "#EC7014",
            "#CC4C02",
            "#993404",
            "#662506",
        ]
        self.cmap = LinearSegmentedColormap.from_list(self.cname, clrs)
        self.cmap.set_bad("#888888")

    def __iridescent(self):
        """
        Define colormap 'iridescent'.
        """
        clrs = [
            "#FEFBE9",
            "#FCF7D5",
            "#F5F3C1",
            "#EAF0B5",
            "#DDECBF",
            "#D0E7CA",
            "#C2E3D2",
            "#B5DDD8",
            "#A8D8DC",
            "#9BD2E1",
            "#8DCBE4",
            "#81C4E7",
            "#7BBCE7",
            "#7EB2E4",
            "#88A5DD",
            "#9398D2",
            "#9B8AC4",
            "#9D7DB2",
            "#9A709E",
            "#906388",
            "#805770",
            "#684957",
            "#46353A",
        ]
        self.cmap = LinearSegmentedColormap.from_list(self.cname, clrs)
        self.cmap.set_bad("#999999")

    def __rainbow_PuRd(self):
        """
        Define colormap 'rainbow_PuRd'.
        """
        clrs = [
            "#6F4C9B",
            "#6059A9",
            "#5568B8",
            "#4E79C5",
            "#4D8AC6",
            "#4E96BC",
            "#549EB3",
            "#59A5A9",
            "#60AB9E",
            "#69B190",
            "#77B77D",
            "#8CBC68",
            "#A6BE54",
            "#BEBC48",
            "#D1B541",
            "#DDAA3C",
            "#E49C39",
            "#E78C35",
            "#E67932",
            "#E4632D",
            "#DF4828",
            "#DA2222",
        ]
        self.cmap = LinearSegmentedColormap.from_list(self.cname, clrs)
        self.cmap.set_bad("#FFFFFF")

    def __rainbow_PuBr(self):
        """
        Define colormap 'rainbow_PuBr'.
        """
        clrs = [
            "#6F4C9B",
            "#6059A9",
            "#5568B8",
            "#4E79C5",
            "#4D8AC6",
            "#4E96BC",
            "#549EB3",
            "#59A5A9",
            "#60AB9E",
            "#69B190",
            "#77B77D",
            "#8CBC68",
            "#A6BE54",
            "#BEBC48",
            "#D1B541",
            "#DDAA3C",
            "#E49C39",
            "#E78C35",
            "#E67932",
            "#E4632D",
            "#DF4828",
            "#DA2222",
            "#B8221E",
            "#95211B",
            "#721E17",
            "#521A13",
        ]
        self.cmap = LinearSegmentedColormap.from_list(self.cname, clrs)
        self.cmap.set_bad("#FFFFFF")

    def __rainbow_WhRd(self):
        """
        Define colormap 'rainbow_WhRd'.
        """
        clrs = [
            "#E8ECFB",
            "#DDD8EF",
            "#D1C1E1",
            "#C3A8D1",
            "#B58FC2",
            "#A778B4",
            "#9B62A7",
            "#8C4E99",
            "#6F4C9B",
            "#6059A9",
            "#5568B8",
            "#4E79C5",
            "#4D8AC6",
            "#4E96BC",
            "#549EB3",
            "#59A5A9",
            "#60AB9E",
            "#69B190",
            "#77B77D",
            "#8CBC68",
            "#A6BE54",
            "#BEBC48",
            "#D1B541",
            "#DDAA3C",
            "#E49C39",
            "#E78C35",
            "#E67932",
            "#E4632D",
            "#DF4828",
            "#DA2222",
        ]
        self.cmap = LinearSegmentedColormap.from_list(self.cname, clrs)
        self.cmap.set_bad("#666666")

    def __rainbow_WhBr(self):
        """
        Define colormap 'rainbow_WhBr'.
        """
        clrs = [
            "#E8ECFB",
            "#DDD8EF",
            "#D1C1E1",
            "#C3A8D1",
            "#B58FC2",
            "#A778B4",
            "#9B62A7",
            "#8C4E99",
            "#6F4C9B",
            "#6059A9",
            "#5568B8",
            "#4E79C5",
            "#4D8AC6",
            "#4E96BC",
            "#549EB3",
            "#59A5A9",
            "#60AB9E",
            "#69B190",
            "#77B77D",
            "#8CBC68",
            "#A6BE54",
            "#BEBC48",
            "#D1B541",
            "#DDAA3C",
            "#E49C39",
            "#E78C35",
            "#E67932",
            "#E4632D",
            "#DF4828",
            "#DA2222",
            "#B8221E",
            "#95211B",
            "#721E17",
            "#521A13",
        ]
        self.cmap = LinearSegmentedColormap.from_list(self.cname, clrs)
        self.cmap.set_bad("#666666")

    def __rainbow_discrete(self, lut=None):
        """
        Define colormap 'rainbow_discrete'.
        """
        clrs = [
            "#E8ECFB",
            "#D9CCE3",
            "#D1BBD7",
            "#CAACCB",
            "#BA8DB4",
            "#AE76A3",
            "#AA6F9E",
            "#994F88",
            "#882E72",
            "#1965B0",
            "#437DBF",
            "#5289C7",
            "#6195CF",
            "#7BAFDE",
            "#4EB265",
            "#90C987",
            "#CAE0AB",
            "#F7F056",
            "#F7CB45",
            "#F6C141",
            "#F4A736",
            "#F1932D",
            "#EE8026",
            "#E8601C",
            "#E65518",
            "#DC050C",
            "#A5170E",
            "#72190E",
            "#42150A",
        ]
        indexes = [
            [9],
            [9, 25],
            [9, 17, 25],
            [9, 14, 17, 25],
            [9, 13, 14, 17, 25],
            [9, 13, 14, 16, 17, 25],
            [8, 9, 13, 14, 16, 17, 25],
            [8, 9, 13, 14, 16, 17, 22, 25],
            [8, 9, 13, 14, 16, 17, 22, 25, 27],
            [8, 9, 13, 14, 16, 17, 20, 23, 25, 27],
            [8, 9, 11, 13, 14, 16, 17, 20, 23, 25, 27],
            [2, 5, 8, 9, 11, 13, 14, 16, 17, 20, 23, 25],
            [2, 5, 8, 9, 11, 13, 14, 15, 16, 17, 20, 23, 25],
            [2, 5, 8, 9, 11, 13, 14, 15, 16, 17, 19, 21, 23, 25],
            [2, 5, 8, 9, 11, 13, 14, 15, 16, 17, 19, 21, 23, 25, 27],
            [2, 4, 6, 8, 9, 11, 13, 14, 15, 16, 17, 19, 21, 23, 25, 27],
            [2, 4, 6, 7, 8, 9, 11, 13, 14, 15, 16, 17, 19, 21, 23, 25, 27],
            [2, 4, 6, 7, 8, 9, 11, 13, 14, 15, 16, 17, 19, 21, 23, 25, 26, 27],
            [1, 3, 4, 6, 7, 8, 9, 11, 13, 14, 15, 16, 17, 19, 21, 23, 25, 26, 27],
            [1, 3, 4, 6, 7, 8, 9, 10, 12, 13, 14, 15, 16, 17, 19, 21, 23, 25, 26, 27],
            [
                1,
                3,
                4,
                6,
                7,
                8,
                9,
                10,
                12,
                13,
                14,
                15,
                16,
                17,
                18,
                20,
                22,
                24,
                25,
                26,
                27,
            ],
            [
                1,
                3,
                4,
                6,
                7,
                8,
                9,
                10,
                12,
                13,
                14,
                15,
                16,
                17,
                18,
                20,
                22,
                24,
                25,
                26,
                27,
                28,
            ],
            [
                0,
                1,
                3,
                4,
                6,
                7,
                8,
                9,
                10,
                12,
                13,
                14,
                15,
                16,
                17,
                18,
                20,
                22,
                24,
                25,
                26,
                27,
                28,
            ],
        ]
        if lut == None or lut < 1 or lut > 23:
            lut = 22
        self.cmap = discretemap(self.cname, [clrs[i] for i in indexes[lut - 1]])
        if lut == 23:
            self.cmap.set_bad("#777777")
        else:
            self.cmap.set_bad("#FFFFFF")

    def show(self):
        """
        List names of defined colormaps.
        """
        print(" ".join(repr(n) for n in self.namelist))

    def get(self, cname="rainbow_PuRd", lut=None):
        """
        Return requested colormap, default is 'rainbow_PuRd'.
        """
        self.cname = cname
        if cname == "rainbow_discrete":
            self.__rainbow_discrete(lut)
        else:
            self.funcdict[cname]()
        return self.cmap

__BuRd()

Define colormap 'BuRd'.

Source code in pyhdx/tol_colors.py
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
def __BuRd(self):
    """
    Define colormap 'BuRd'.
    """
    clrs = [
        "#2166AC",
        "#4393C3",
        "#92C5DE",
        "#D1E5F0",
        "#F7F7F7",
        "#FDDBC7",
        "#F4A582",
        "#D6604D",
        "#B2182B",
    ]
    self.cmap = LinearSegmentedColormap.from_list(self.cname, clrs)
    self.cmap.set_bad("#FFEE99")

__BuRd_discrete()

Define colormap 'BuRd_discrete'.

Source code in pyhdx/tol_colors.py
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
def __BuRd_discrete(self):
    """
    Define colormap 'BuRd_discrete'.
    """
    clrs = [
        "#2166AC",
        "#4393C3",
        "#92C5DE",
        "#D1E5F0",
        "#F7F7F7",
        "#FDDBC7",
        "#F4A582",
        "#D6604D",
        "#B2182B",
    ]
    self.cmap = discretemap(self.cname, clrs)
    self.cmap.set_bad("#FFEE99")

__PRGn()

Define colormap 'PRGn'.

Source code in pyhdx/tol_colors.py
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
def __PRGn(self):
    """
    Define colormap 'PRGn'.
    """
    clrs = [
        "#762A83",
        "#9970AB",
        "#C2A5CF",
        "#E7D4E8",
        "#F7F7F7",
        "#D9F0D3",
        "#ACD39E",
        "#5AAE61",
        "#1B7837",
    ]
    self.cmap = LinearSegmentedColormap.from_list(self.cname, clrs)
    self.cmap.set_bad("#FFEE99")

__PRGn_discrete()

Define colormap 'PRGn_discrete'.

Source code in pyhdx/tol_colors.py
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
def __PRGn_discrete(self):
    """
    Define colormap 'PRGn_discrete'.
    """
    clrs = [
        "#762A83",
        "#9970AB",
        "#C2A5CF",
        "#E7D4E8",
        "#F7F7F7",
        "#D9F0D3",
        "#ACD39E",
        "#5AAE61",
        "#1B7837",
    ]
    self.cmap = discretemap(self.cname, clrs)
    self.cmap.set_bad("#FFEE99")

__WhOrBr()

Define colormap 'WhOrBr'.

Source code in pyhdx/tol_colors.py
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
def __WhOrBr(self):
    """
    Define colormap 'WhOrBr'.
    """
    clrs = [
        "#FFFFFF",
        "#FFF7BC",
        "#FEE391",
        "#FEC44F",
        "#FB9A29",
        "#EC7014",
        "#CC4C02",
        "#993404",
        "#662506",
    ]
    self.cmap = LinearSegmentedColormap.from_list(self.cname, clrs)
    self.cmap.set_bad("#888888")

__YlOrBr()

Define colormap 'YlOrBr'.

Source code in pyhdx/tol_colors.py
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
def __YlOrBr(self):
    """
    Define colormap 'YlOrBr'.
    """
    clrs = [
        "#FFFFE5",
        "#FFF7BC",
        "#FEE391",
        "#FEC44F",
        "#FB9A29",
        "#EC7014",
        "#CC4C02",
        "#993404",
        "#662506",
    ]
    self.cmap = LinearSegmentedColormap.from_list(self.cname, clrs)
    self.cmap.set_bad("#888888")

__YlOrBr_discrete()

Define colormap 'YlOrBr_discrete'.

Source code in pyhdx/tol_colors.py
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
def __YlOrBr_discrete(self):
    """
    Define colormap 'YlOrBr_discrete'.
    """
    clrs = [
        "#FFFFE5",
        "#FFF7BC",
        "#FEE391",
        "#FEC44F",
        "#FB9A29",
        "#EC7014",
        "#CC4C02",
        "#993404",
        "#662506",
    ]
    self.cmap = discretemap(self.cname, clrs)
    self.cmap.set_bad("#888888")

__init__()

Source code in pyhdx/tol_colors.py
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
def __init__(self):
    """ """
    self.cmap = None
    self.cname = None
    self.namelist = (
        "sunset_discrete",
        "sunset",
        "BuRd_discrete",
        "BuRd",
        "PRGn_discrete",
        "PRGn",
        "YlOrBr_discrete",
        "YlOrBr",
        "WhOrBr",
        "iridescent",
        "rainbow_PuRd",
        "rainbow_PuBr",
        "rainbow_WhRd",
        "rainbow_WhBr",
        "rainbow_discrete",
    )

    self.funcdict = dict(
        zip(
            self.namelist,
            (
                self.__sunset_discrete,
                self.__sunset,
                self.__BuRd_discrete,
                self.__BuRd,
                self.__PRGn_discrete,
                self.__PRGn,
                self.__YlOrBr_discrete,
                self.__YlOrBr,
                self.__WhOrBr,
                self.__iridescent,
                self.__rainbow_PuRd,
                self.__rainbow_PuBr,
                self.__rainbow_WhRd,
                self.__rainbow_WhBr,
                self.__rainbow_discrete,
            ),
        )
    )

__iridescent()

Define colormap 'iridescent'.

Source code in pyhdx/tol_colors.py
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
def __iridescent(self):
    """
    Define colormap 'iridescent'.
    """
    clrs = [
        "#FEFBE9",
        "#FCF7D5",
        "#F5F3C1",
        "#EAF0B5",
        "#DDECBF",
        "#D0E7CA",
        "#C2E3D2",
        "#B5DDD8",
        "#A8D8DC",
        "#9BD2E1",
        "#8DCBE4",
        "#81C4E7",
        "#7BBCE7",
        "#7EB2E4",
        "#88A5DD",
        "#9398D2",
        "#9B8AC4",
        "#9D7DB2",
        "#9A709E",
        "#906388",
        "#805770",
        "#684957",
        "#46353A",
    ]
    self.cmap = LinearSegmentedColormap.from_list(self.cname, clrs)
    self.cmap.set_bad("#999999")

__rainbow_PuBr()

Define colormap 'rainbow_PuBr'.

Source code in pyhdx/tol_colors.py
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
def __rainbow_PuBr(self):
    """
    Define colormap 'rainbow_PuBr'.
    """
    clrs = [
        "#6F4C9B",
        "#6059A9",
        "#5568B8",
        "#4E79C5",
        "#4D8AC6",
        "#4E96BC",
        "#549EB3",
        "#59A5A9",
        "#60AB9E",
        "#69B190",
        "#77B77D",
        "#8CBC68",
        "#A6BE54",
        "#BEBC48",
        "#D1B541",
        "#DDAA3C",
        "#E49C39",
        "#E78C35",
        "#E67932",
        "#E4632D",
        "#DF4828",
        "#DA2222",
        "#B8221E",
        "#95211B",
        "#721E17",
        "#521A13",
    ]
    self.cmap = LinearSegmentedColormap.from_list(self.cname, clrs)
    self.cmap.set_bad("#FFFFFF")

__rainbow_PuRd()

Define colormap 'rainbow_PuRd'.

Source code in pyhdx/tol_colors.py
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
def __rainbow_PuRd(self):
    """
    Define colormap 'rainbow_PuRd'.
    """
    clrs = [
        "#6F4C9B",
        "#6059A9",
        "#5568B8",
        "#4E79C5",
        "#4D8AC6",
        "#4E96BC",
        "#549EB3",
        "#59A5A9",
        "#60AB9E",
        "#69B190",
        "#77B77D",
        "#8CBC68",
        "#A6BE54",
        "#BEBC48",
        "#D1B541",
        "#DDAA3C",
        "#E49C39",
        "#E78C35",
        "#E67932",
        "#E4632D",
        "#DF4828",
        "#DA2222",
    ]
    self.cmap = LinearSegmentedColormap.from_list(self.cname, clrs)
    self.cmap.set_bad("#FFFFFF")

__rainbow_WhBr()

Define colormap 'rainbow_WhBr'.

Source code in pyhdx/tol_colors.py
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
def __rainbow_WhBr(self):
    """
    Define colormap 'rainbow_WhBr'.
    """
    clrs = [
        "#E8ECFB",
        "#DDD8EF",
        "#D1C1E1",
        "#C3A8D1",
        "#B58FC2",
        "#A778B4",
        "#9B62A7",
        "#8C4E99",
        "#6F4C9B",
        "#6059A9",
        "#5568B8",
        "#4E79C5",
        "#4D8AC6",
        "#4E96BC",
        "#549EB3",
        "#59A5A9",
        "#60AB9E",
        "#69B190",
        "#77B77D",
        "#8CBC68",
        "#A6BE54",
        "#BEBC48",
        "#D1B541",
        "#DDAA3C",
        "#E49C39",
        "#E78C35",
        "#E67932",
        "#E4632D",
        "#DF4828",
        "#DA2222",
        "#B8221E",
        "#95211B",
        "#721E17",
        "#521A13",
    ]
    self.cmap = LinearSegmentedColormap.from_list(self.cname, clrs)
    self.cmap.set_bad("#666666")

__rainbow_WhRd()

Define colormap 'rainbow_WhRd'.

Source code in pyhdx/tol_colors.py
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
def __rainbow_WhRd(self):
    """
    Define colormap 'rainbow_WhRd'.
    """
    clrs = [
        "#E8ECFB",
        "#DDD8EF",
        "#D1C1E1",
        "#C3A8D1",
        "#B58FC2",
        "#A778B4",
        "#9B62A7",
        "#8C4E99",
        "#6F4C9B",
        "#6059A9",
        "#5568B8",
        "#4E79C5",
        "#4D8AC6",
        "#4E96BC",
        "#549EB3",
        "#59A5A9",
        "#60AB9E",
        "#69B190",
        "#77B77D",
        "#8CBC68",
        "#A6BE54",
        "#BEBC48",
        "#D1B541",
        "#DDAA3C",
        "#E49C39",
        "#E78C35",
        "#E67932",
        "#E4632D",
        "#DF4828",
        "#DA2222",
    ]
    self.cmap = LinearSegmentedColormap.from_list(self.cname, clrs)
    self.cmap.set_bad("#666666")

__rainbow_discrete(lut=None)

Define colormap 'rainbow_discrete'.

Source code in pyhdx/tol_colors.py
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
def __rainbow_discrete(self, lut=None):
    """
    Define colormap 'rainbow_discrete'.
    """
    clrs = [
        "#E8ECFB",
        "#D9CCE3",
        "#D1BBD7",
        "#CAACCB",
        "#BA8DB4",
        "#AE76A3",
        "#AA6F9E",
        "#994F88",
        "#882E72",
        "#1965B0",
        "#437DBF",
        "#5289C7",
        "#6195CF",
        "#7BAFDE",
        "#4EB265",
        "#90C987",
        "#CAE0AB",
        "#F7F056",
        "#F7CB45",
        "#F6C141",
        "#F4A736",
        "#F1932D",
        "#EE8026",
        "#E8601C",
        "#E65518",
        "#DC050C",
        "#A5170E",
        "#72190E",
        "#42150A",
    ]
    indexes = [
        [9],
        [9, 25],
        [9, 17, 25],
        [9, 14, 17, 25],
        [9, 13, 14, 17, 25],
        [9, 13, 14, 16, 17, 25],
        [8, 9, 13, 14, 16, 17, 25],
        [8, 9, 13, 14, 16, 17, 22, 25],
        [8, 9, 13, 14, 16, 17, 22, 25, 27],
        [8, 9, 13, 14, 16, 17, 20, 23, 25, 27],
        [8, 9, 11, 13, 14, 16, 17, 20, 23, 25, 27],
        [2, 5, 8, 9, 11, 13, 14, 16, 17, 20, 23, 25],
        [2, 5, 8, 9, 11, 13, 14, 15, 16, 17, 20, 23, 25],
        [2, 5, 8, 9, 11, 13, 14, 15, 16, 17, 19, 21, 23, 25],
        [2, 5, 8, 9, 11, 13, 14, 15, 16, 17, 19, 21, 23, 25, 27],
        [2, 4, 6, 8, 9, 11, 13, 14, 15, 16, 17, 19, 21, 23, 25, 27],
        [2, 4, 6, 7, 8, 9, 11, 13, 14, 15, 16, 17, 19, 21, 23, 25, 27],
        [2, 4, 6, 7, 8, 9, 11, 13, 14, 15, 16, 17, 19, 21, 23, 25, 26, 27],
        [1, 3, 4, 6, 7, 8, 9, 11, 13, 14, 15, 16, 17, 19, 21, 23, 25, 26, 27],
        [1, 3, 4, 6, 7, 8, 9, 10, 12, 13, 14, 15, 16, 17, 19, 21, 23, 25, 26, 27],
        [
            1,
            3,
            4,
            6,
            7,
            8,
            9,
            10,
            12,
            13,
            14,
            15,
            16,
            17,
            18,
            20,
            22,
            24,
            25,
            26,
            27,
        ],
        [
            1,
            3,
            4,
            6,
            7,
            8,
            9,
            10,
            12,
            13,
            14,
            15,
            16,
            17,
            18,
            20,
            22,
            24,
            25,
            26,
            27,
            28,
        ],
        [
            0,
            1,
            3,
            4,
            6,
            7,
            8,
            9,
            10,
            12,
            13,
            14,
            15,
            16,
            17,
            18,
            20,
            22,
            24,
            25,
            26,
            27,
            28,
        ],
    ]
    if lut == None or lut < 1 or lut > 23:
        lut = 22
    self.cmap = discretemap(self.cname, [clrs[i] for i in indexes[lut - 1]])
    if lut == 23:
        self.cmap.set_bad("#777777")
    else:
        self.cmap.set_bad("#FFFFFF")

__sunset()

Define colormap 'sunset'.

Source code in pyhdx/tol_colors.py
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
def __sunset(self):
    """
    Define colormap 'sunset'.
    """
    clrs = [
        "#364B9A",
        "#4A7BB7",
        "#6EA6CD",
        "#98CAE1",
        "#C2E4EF",
        "#EAECCC",
        "#FEDA8B",
        "#FDB366",
        "#F67E4B",
        "#DD3D2D",
        "#A50026",
    ]
    self.cmap = LinearSegmentedColormap.from_list(self.cname, clrs)
    self.cmap.set_bad("#FFFFFF")

__sunset_discrete()

Define colormap 'sunset_discrete'.

Source code in pyhdx/tol_colors.py
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
def __sunset_discrete(self):
    """
    Define colormap 'sunset_discrete'.
    """
    clrs = [
        "#364B9A",
        "#4A7BB7",
        "#6EA6CD",
        "#98CAE1",
        "#C2E4EF",
        "#EAECCC",
        "#FEDA8B",
        "#FDB366",
        "#F67E4B",
        "#DD3D2D",
        "#A50026",
    ]
    self.cmap = discretemap(self.cname, clrs)
    self.cmap.set_bad("#FFFFFF")

get(cname='rainbow_PuRd', lut=None)

Return requested colormap, default is 'rainbow_PuRd'.

Source code in pyhdx/tol_colors.py
568
569
570
571
572
573
574
575
576
577
def get(self, cname="rainbow_PuRd", lut=None):
    """
    Return requested colormap, default is 'rainbow_PuRd'.
    """
    self.cname = cname
    if cname == "rainbow_discrete":
        self.__rainbow_discrete(lut)
    else:
        self.funcdict[cname]()
    return self.cmap

show()

List names of defined colormaps.

Source code in pyhdx/tol_colors.py
562
563
564
565
566
def show(self):
    """
    List names of defined colormaps.
    """
    print(" ".join(repr(n) for n in self.namelist))

discretemap(colormap, hexclrs)

Produce a colormap from a list of discrete colors without interpolation.

Source code in pyhdx/tol_colors.py
15
16
17
18
19
20
21
22
23
24
25
26
def discretemap(colormap, hexclrs):
    """
    Produce a colormap from a list of discrete colors without interpolation.
    """
    clrs = to_rgba_array(hexclrs)
    clrs = np.vstack([clrs[0], clrs, clrs[-1]])
    cdict = {}
    for ki, key in enumerate(("red", "green", "blue")):
        cdict[key] = [
            (i / (len(clrs) - 2.0), clrs[i, ki], clrs[i + 1, ki]) for i in range(len(clrs) - 1)
        ]
    return LinearSegmentedColormap(colormap, cdict)

tol_cmap(colormap=None, lut=None)

Continuous and discrete color sets for ordered data.

Return a matplotlib colormap. Parameter lut is ignored for all colormaps except 'rainbow_discrete'.

Source code in pyhdx/tol_colors.py
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
def tol_cmap(colormap=None, lut=None):
    """
    Continuous and discrete color sets for ordered data.

    Return a matplotlib colormap.
    Parameter lut is ignored for all colormaps except 'rainbow_discrete'.
    """
    obj = TOLcmaps()
    if colormap == None:
        return obj.namelist
    if colormap not in obj.namelist:
        colormap = "rainbow_PuRd"
        print(
            "*** Warning: requested colormap not defined,",
            "known colormaps are {}.".format(obj.namelist),
            "Using {}.".format(colormap),
        )
    return obj.get(colormap, lut)

tol_cset(colorset=None)

Discrete color sets for qualitative data.

Define a namedtuple instance with the colors. Examples for: cset = tol_cset() - cset.red and cset[1] give the same color (in default 'bright' colorset) - cset._fields gives a tuple with all color names - list(cset) gives a list with all colors

Source code in pyhdx/tol_colors.py
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
def tol_cset(colorset=None):
    """
    Discrete color sets for qualitative data.

    Define a namedtuple instance with the colors.
    Examples for: cset = tol_cset(<scheme>)
      - cset.red and cset[1] give the same color (in default 'bright' colorset)
      - cset._fields gives a tuple with all color names
      - list(cset) gives a list with all colors
    """
    from collections import namedtuple

    namelist = (
        "bright",
        "high-contrast",
        "vibrant",
        "muted",
        "medium-contrast",
        "light",
    )
    if colorset == None:
        return namelist
    if colorset not in namelist:
        colorset = "bright"
        print(
            "*** Warning: requested colorset not defined,",
            "known colorsets are {}.".format(namelist),
            "Using {}.".format(colorset),
        )

    if colorset == "bright":
        cset = namedtuple("Bcset", "blue red green yellow cyan purple grey black")
        return cset(
            "#4477AA",
            "#EE6677",
            "#228833",
            "#CCBB44",
            "#66CCEE",
            "#AA3377",
            "#BBBBBB",
            "#000000",
        )

    if colorset == "high-contrast":
        cset = namedtuple("Hcset", "blue yellow red black")
        return cset("#004488", "#DDAA33", "#BB5566", "#000000")

    if colorset == "vibrant":
        cset = namedtuple("Vcset", "orange blue cyan magenta red teal grey black")
        return cset(
            "#EE7733",
            "#0077BB",
            "#33BBEE",
            "#EE3377",
            "#CC3311",
            "#009988",
            "#BBBBBB",
            "#000000",
        )

    if colorset == "muted":
        cset = namedtuple(
            "Mcset",
            "rose indigo sand green cyan wine teal olive purple pale_grey black",
        )
        return cset(
            "#CC6677",
            "#332288",
            "#DDCC77",
            "#117733",
            "#88CCEE",
            "#882255",
            "#44AA99",
            "#999933",
            "#AA4499",
            "#DDDDDD",
            "#000000",
        )

    if colorset == "medium-contrast":
        cset = namedtuple(
            "Mcset",
            "light_blue dark_blue light_yellow dark_red dark_yellow light_red black",
        )
        return cset("#6699CC", "#004488", "#EECC66", "#994455", "#997700", "#EE99AA", "#000000")

    if colorset == "light":
        cset = namedtuple(
            "Lcset",
            "light_blue orange light_yellow pink light_cyan mint pear olive pale_grey black",
        )
        return cset(
            "#77AADD",
            "#EE8866",
            "#EEDD88",
            "#FFAABB",
            "#99DDFF",
            "#44BB99",
            "#BBCC33",
            "#AAAA00",
            "#DDDDDD",
            "#000000",
        )