mergeron 2024.739097.4__py3-none-any.whl → 2024.739099.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of mergeron might be problematic. Click here for more details.

@@ -1,848 +0,0 @@
1
- """
2
- Definition of colour schemes for lines and maps that also work for colour-blind
3
- people. See https://personal.sron.nl/~pault/ for background information and
4
- best usage of the schemes.
5
-
6
- Copyright (c) 2022, Paul Tol
7
- All rights reserved.
8
-
9
- License: Standard 3-clause BSD
10
- """
11
-
12
- __version__ = "2022.10"
13
-
14
- from collections import namedtuple
15
- from collections.abc import Callable, Sequence
16
- from typing import Literal
17
-
18
- import numpy as np
19
- from matplotlib.colors import LinearSegmentedColormap, to_rgba_array
20
-
21
-
22
- def discretemap(colormap: str, hexclrs: Sequence[str]) -> LinearSegmentedColormap:
23
- """
24
- Produce a colormap from a list of discrete colors without interpolation.
25
- """
26
- clrs = to_rgba_array(hexclrs)
27
- clrs = np.vstack([clrs[0], clrs, clrs[-1]])
28
- cdict: dict[
29
- Literal["red", "green", "blue", "alpha"], Sequence[tuple[float, ...]]
30
- ] = {}
31
- for ki, key in enumerate(("red", "green", "blue")):
32
- cdict[key] = [ # type: ignore
33
- (i / (len(clrs) - 2.0), clrs[i, ki], clrs[i + 1, ki])
34
- for i in range(len(clrs) - 1)
35
- ]
36
- return LinearSegmentedColormap(colormap, cdict)
37
-
38
-
39
- class TOLcmaps:
40
- def __init__(self) -> None:
41
- """
42
- Class TOLcmaps definition.
43
-
44
- Attributes
45
- ----------
46
- cmap
47
- A matploltib colormap
48
-
49
- cname
50
- Colormap name
51
-
52
- namelist
53
- A list of colormap names
54
- """
55
- # self.cmap: LinearSegmentedColormap | None = None
56
- self.cname: str = ""
57
- self.namelist: Sequence[str] = (
58
- "sunset_discrete",
59
- "sunset",
60
- "nightfall_discrete",
61
- "nightfall",
62
- "BuRd_discrete",
63
- "BuRd",
64
- "PRGn_discrete",
65
- "PRGn",
66
- "YlOrBr_discrete",
67
- "YlOrBr",
68
- "WhOrBr",
69
- "iridescent",
70
- "rainbow_PuRd",
71
- "rainbow_PuBr",
72
- "rainbow_WhRd",
73
- "rainbow_WhBr",
74
- "rainbow_discrete",
75
- )
76
-
77
- self.funcdict: dict[str, Callable[[], None] | Callable[[None | int], None]] = (
78
- dict(
79
- zip(
80
- self.namelist,
81
- (
82
- self.__sunset_discrete,
83
- self.__sunset,
84
- self.__nightfall_discrete,
85
- self.__nightfall,
86
- self.__BuRd_discrete,
87
- self.__BuRd,
88
- self.__PRGn_discrete,
89
- self.__PRGn,
90
- self.__YlOrBr_discrete,
91
- self.__YlOrBr,
92
- self.__WhOrBr,
93
- self.__iridescent,
94
- self.__rainbow_PuRd,
95
- self.__rainbow_PuBr,
96
- self.__rainbow_WhRd,
97
- self.__rainbow_WhBr,
98
- self.__rainbow_discrete,
99
- ),
100
- )
101
- )
102
- )
103
-
104
- def __sunset_discrete(self) -> None:
105
- """
106
- Define colormap 'sunset_discrete'.
107
- """
108
- clrs = [
109
- "#364B9A",
110
- "#4A7BB7",
111
- "#6EA6CD",
112
- "#98CAE1",
113
- "#C2E4EF",
114
- "#EAECCC",
115
- "#FEDA8B",
116
- "#FDB366",
117
- "#F67E4B",
118
- "#DD3D2D",
119
- "#A50026",
120
- ]
121
- self.cmap = discretemap(self.cname, clrs)
122
- self.cmap.set_bad("#FFFFFF")
123
-
124
- def __sunset(self) -> None:
125
- """
126
- Define colormap 'sunset'.
127
- """
128
- clrs = [
129
- "#364B9A",
130
- "#4A7BB7",
131
- "#6EA6CD",
132
- "#98CAE1",
133
- "#C2E4EF",
134
- "#EAECCC",
135
- "#FEDA8B",
136
- "#FDB366",
137
- "#F67E4B",
138
- "#DD3D2D",
139
- "#A50026",
140
- ]
141
- self.cmap = LinearSegmentedColormap.from_list(self.cname, clrs)
142
- self.cmap.set_bad("#FFFFFF")
143
-
144
- def __nightfall_discrete(self) -> None:
145
- """
146
- Define colormap 'nighfall_discrete'.
147
- """
148
- clrs = [
149
- "#125A56",
150
- "#238F9D",
151
- "#60BCE9",
152
- "#C6DBED",
153
- "#ECEADA",
154
- "#F9D576",
155
- "#FD9A44",
156
- "#E94C1F",
157
- "#A01813",
158
- ]
159
- self.cmap = discretemap(self.cname, clrs)
160
- self.cmap.set_bad("#FFFFFF")
161
-
162
- def __nightfall(self) -> None:
163
- """
164
- Define colormap 'nightfall'.
165
- """
166
- clrs = [
167
- "#125A56",
168
- "#00767B",
169
- "#238F9D",
170
- "#42A7C6",
171
- "#60BCE9",
172
- "#9DCCEF",
173
- "#C6DBED",
174
- "#DEE6E7",
175
- "#ECEADA",
176
- "#F0E6B2",
177
- "#F9D576",
178
- "#FFB954",
179
- "#FD9A44",
180
- "#F57634",
181
- "#E94C1F",
182
- "#D11807",
183
- "#A01813",
184
- ]
185
- self.cmap = LinearSegmentedColormap.from_list(self.cname, clrs)
186
- self.cmap.set_bad("#FFFFFF")
187
-
188
- def __BuRd_discrete(self) -> None:
189
- """
190
- Define colormap 'BuRd_discrete'.
191
- """
192
- clrs = [
193
- "#2166AC",
194
- "#4393C3",
195
- "#92C5DE",
196
- "#D1E5F0",
197
- "#F7F7F7",
198
- "#FDDBC7",
199
- "#F4A582",
200
- "#D6604D",
201
- "#B2182B",
202
- ]
203
- self.cmap = discretemap(self.cname, clrs)
204
- self.cmap.set_bad("#FFEE99")
205
-
206
- def __BuRd(self) -> None:
207
- """
208
- Define colormap 'BuRd'.
209
- """
210
- clrs = [
211
- "#2166AC",
212
- "#4393C3",
213
- "#92C5DE",
214
- "#D1E5F0",
215
- "#F7F7F7",
216
- "#FDDBC7",
217
- "#F4A582",
218
- "#D6604D",
219
- "#B2182B",
220
- ]
221
- self.cmap = LinearSegmentedColormap.from_list(self.cname, clrs)
222
- self.cmap.set_bad("#FFEE99")
223
-
224
- def __PRGn_discrete(self) -> None:
225
- """
226
- Define colormap 'PRGn_discrete'.
227
- """
228
- clrs = [
229
- "#762A83",
230
- "#9970AB",
231
- "#C2A5CF",
232
- "#E7D4E8",
233
- "#F7F7F7",
234
- "#D9F0D3",
235
- "#ACD39E",
236
- "#5AAE61",
237
- "#1B7837",
238
- ]
239
- self.cmap = discretemap(self.cname, clrs)
240
- self.cmap.set_bad("#FFEE99")
241
-
242
- def __PRGn(self) -> None:
243
- """
244
- Define colormap 'PRGn'.
245
- """
246
- clrs = [
247
- "#762A83",
248
- "#9970AB",
249
- "#C2A5CF",
250
- "#E7D4E8",
251
- "#F7F7F7",
252
- "#D9F0D3",
253
- "#ACD39E",
254
- "#5AAE61",
255
- "#1B7837",
256
- ]
257
- self.cmap = LinearSegmentedColormap.from_list(self.cname, clrs)
258
- self.cmap.set_bad("#FFEE99")
259
-
260
- def __YlOrBr_discrete(self) -> None:
261
- """
262
- Define colormap 'YlOrBr_discrete'.
263
- """
264
- clrs = [
265
- "#FFFFE5",
266
- "#FFF7BC",
267
- "#FEE391",
268
- "#FEC44F",
269
- "#FB9A29",
270
- "#EC7014",
271
- "#CC4C02",
272
- "#993404",
273
- "#662506",
274
- ]
275
- self.cmap = discretemap(self.cname, clrs)
276
- self.cmap.set_bad("#888888")
277
-
278
- def __YlOrBr(self) -> None:
279
- """
280
- Define colormap 'YlOrBr'.
281
- """
282
- clrs = [
283
- "#FFFFE5",
284
- "#FFF7BC",
285
- "#FEE391",
286
- "#FEC44F",
287
- "#FB9A29",
288
- "#EC7014",
289
- "#CC4C02",
290
- "#993404",
291
- "#662506",
292
- ]
293
- self.cmap = LinearSegmentedColormap.from_list(self.cname, clrs)
294
- self.cmap.set_bad("#888888")
295
-
296
- def __WhOrBr(self) -> None:
297
- """
298
- Define colormap 'WhOrBr'.
299
- """
300
- clrs = [
301
- "#FFFFFF",
302
- "#FFF7BC",
303
- "#FEE391",
304
- "#FEC44F",
305
- "#FB9A29",
306
- "#EC7014",
307
- "#CC4C02",
308
- "#993404",
309
- "#662506",
310
- ]
311
- self.cmap = LinearSegmentedColormap.from_list(self.cname, clrs)
312
- self.cmap.set_bad("#888888")
313
-
314
- def __iridescent(self) -> None:
315
- """
316
- Define colormap 'iridescent'.
317
- """
318
- clrs = [
319
- "#FEFBE9",
320
- "#FCF7D5",
321
- "#F5F3C1",
322
- "#EAF0B5",
323
- "#DDECBF",
324
- "#D0E7CA",
325
- "#C2E3D2",
326
- "#B5DDD8",
327
- "#A8D8DC",
328
- "#9BD2E1",
329
- "#8DCBE4",
330
- "#81C4E7",
331
- "#7BBCE7",
332
- "#7EB2E4",
333
- "#88A5DD",
334
- "#9398D2",
335
- "#9B8AC4",
336
- "#9D7DB2",
337
- "#9A709E",
338
- "#906388",
339
- "#805770",
340
- "#684957",
341
- "#46353A",
342
- ]
343
- self.cmap = LinearSegmentedColormap.from_list(self.cname, clrs)
344
- self.cmap.set_bad("#999999")
345
-
346
- def __rainbow_PuRd(self) -> None:
347
- """
348
- Define colormap 'rainbow_PuRd'.
349
- """
350
- clrs = [
351
- "#6F4C9B",
352
- "#6059A9",
353
- "#5568B8",
354
- "#4E79C5",
355
- "#4D8AC6",
356
- "#4E96BC",
357
- "#549EB3",
358
- "#59A5A9",
359
- "#60AB9E",
360
- "#69B190",
361
- "#77B77D",
362
- "#8CBC68",
363
- "#A6BE54",
364
- "#BEBC48",
365
- "#D1B541",
366
- "#DDAA3C",
367
- "#E49C39",
368
- "#E78C35",
369
- "#E67932",
370
- "#E4632D",
371
- "#DF4828",
372
- "#DA2222",
373
- ]
374
- self.cmap = LinearSegmentedColormap.from_list(self.cname, clrs)
375
- self.cmap.set_bad("#FFFFFF")
376
-
377
- def __rainbow_PuBr(self) -> None:
378
- """
379
- Define colormap 'rainbow_PuBr'.
380
- """
381
- clrs = [
382
- "#6F4C9B",
383
- "#6059A9",
384
- "#5568B8",
385
- "#4E79C5",
386
- "#4D8AC6",
387
- "#4E96BC",
388
- "#549EB3",
389
- "#59A5A9",
390
- "#60AB9E",
391
- "#69B190",
392
- "#77B77D",
393
- "#8CBC68",
394
- "#A6BE54",
395
- "#BEBC48",
396
- "#D1B541",
397
- "#DDAA3C",
398
- "#E49C39",
399
- "#E78C35",
400
- "#E67932",
401
- "#E4632D",
402
- "#DF4828",
403
- "#DA2222",
404
- "#B8221E",
405
- "#95211B",
406
- "#721E17",
407
- "#521A13",
408
- ]
409
- self.cmap = LinearSegmentedColormap.from_list(self.cname, clrs)
410
- self.cmap.set_bad("#FFFFFF")
411
-
412
- def __rainbow_WhRd(self) -> None:
413
- """
414
- Define colormap 'rainbow_WhRd'.
415
- """
416
- clrs = [
417
- "#E8ECFB",
418
- "#DDD8EF",
419
- "#D1C1E1",
420
- "#C3A8D1",
421
- "#B58FC2",
422
- "#A778B4",
423
- "#9B62A7",
424
- "#8C4E99",
425
- "#6F4C9B",
426
- "#6059A9",
427
- "#5568B8",
428
- "#4E79C5",
429
- "#4D8AC6",
430
- "#4E96BC",
431
- "#549EB3",
432
- "#59A5A9",
433
- "#60AB9E",
434
- "#69B190",
435
- "#77B77D",
436
- "#8CBC68",
437
- "#A6BE54",
438
- "#BEBC48",
439
- "#D1B541",
440
- "#DDAA3C",
441
- "#E49C39",
442
- "#E78C35",
443
- "#E67932",
444
- "#E4632D",
445
- "#DF4828",
446
- "#DA2222",
447
- ]
448
- self.cmap = LinearSegmentedColormap.from_list(self.cname, clrs)
449
- self.cmap.set_bad("#666666")
450
-
451
- def __rainbow_WhBr(self) -> None:
452
- """
453
- Define colormap 'rainbow_WhBr'.
454
- """
455
- clrs = [
456
- "#E8ECFB",
457
- "#DDD8EF",
458
- "#D1C1E1",
459
- "#C3A8D1",
460
- "#B58FC2",
461
- "#A778B4",
462
- "#9B62A7",
463
- "#8C4E99",
464
- "#6F4C9B",
465
- "#6059A9",
466
- "#5568B8",
467
- "#4E79C5",
468
- "#4D8AC6",
469
- "#4E96BC",
470
- "#549EB3",
471
- "#59A5A9",
472
- "#60AB9E",
473
- "#69B190",
474
- "#77B77D",
475
- "#8CBC68",
476
- "#A6BE54",
477
- "#BEBC48",
478
- "#D1B541",
479
- "#DDAA3C",
480
- "#E49C39",
481
- "#E78C35",
482
- "#E67932",
483
- "#E4632D",
484
- "#DF4828",
485
- "#DA2222",
486
- "#B8221E",
487
- "#95211B",
488
- "#721E17",
489
- "#521A13",
490
- ]
491
- self.cmap = LinearSegmentedColormap.from_list(self.cname, clrs)
492
- self.cmap.set_bad("#666666")
493
-
494
- def __rainbow_discrete(self, lut: int | None = None) -> None:
495
- """
496
- Define colormap 'rainbow_discrete'.
497
- """
498
- clrs = [
499
- "#E8ECFB",
500
- "#D9CCE3",
501
- "#D1BBD7",
502
- "#CAACCB",
503
- "#BA8DB4",
504
- "#AE76A3",
505
- "#AA6F9E",
506
- "#994F88",
507
- "#882E72",
508
- "#1965B0",
509
- "#437DBF",
510
- "#5289C7",
511
- "#6195CF",
512
- "#7BAFDE",
513
- "#4EB265",
514
- "#90C987",
515
- "#CAE0AB",
516
- "#F7F056",
517
- "#F7CB45",
518
- "#F6C141",
519
- "#F4A736",
520
- "#F1932D",
521
- "#EE8026",
522
- "#E8601C",
523
- "#E65518",
524
- "#DC050C",
525
- "#A5170E",
526
- "#72190E",
527
- "#42150A",
528
- ]
529
- indexes = [
530
- [9],
531
- [9, 25],
532
- [9, 17, 25],
533
- [9, 14, 17, 25],
534
- [9, 13, 14, 17, 25],
535
- [9, 13, 14, 16, 17, 25],
536
- [8, 9, 13, 14, 16, 17, 25],
537
- [8, 9, 13, 14, 16, 17, 22, 25],
538
- [8, 9, 13, 14, 16, 17, 22, 25, 27],
539
- [8, 9, 13, 14, 16, 17, 20, 23, 25, 27],
540
- [8, 9, 11, 13, 14, 16, 17, 20, 23, 25, 27],
541
- [2, 5, 8, 9, 11, 13, 14, 16, 17, 20, 23, 25],
542
- [2, 5, 8, 9, 11, 13, 14, 15, 16, 17, 20, 23, 25],
543
- [2, 5, 8, 9, 11, 13, 14, 15, 16, 17, 19, 21, 23, 25],
544
- [2, 5, 8, 9, 11, 13, 14, 15, 16, 17, 19, 21, 23, 25, 27],
545
- [2, 4, 6, 8, 9, 11, 13, 14, 15, 16, 17, 19, 21, 23, 25, 27],
546
- [2, 4, 6, 7, 8, 9, 11, 13, 14, 15, 16, 17, 19, 21, 23, 25, 27],
547
- [2, 4, 6, 7, 8, 9, 11, 13, 14, 15, 16, 17, 19, 21, 23, 25, 26, 27],
548
- [1, 3, 4, 6, 7, 8, 9, 11, 13, 14, 15, 16, 17, 19, 21, 23, 25, 26, 27],
549
- [1, 3, 4, 6, 7, 8, 9, 10, 12, 13, 14, 15, 16, 17, 19, 21, 23, 25, 26, 27],
550
- [
551
- 1,
552
- 3,
553
- 4,
554
- 6,
555
- 7,
556
- 8,
557
- 9,
558
- 10,
559
- 12,
560
- 13,
561
- 14,
562
- 15,
563
- 16,
564
- 17,
565
- 18,
566
- 20,
567
- 22,
568
- 24,
569
- 25,
570
- 26,
571
- 27,
572
- ],
573
- [
574
- 1,
575
- 3,
576
- 4,
577
- 6,
578
- 7,
579
- 8,
580
- 9,
581
- 10,
582
- 12,
583
- 13,
584
- 14,
585
- 15,
586
- 16,
587
- 17,
588
- 18,
589
- 20,
590
- 22,
591
- 24,
592
- 25,
593
- 26,
594
- 27,
595
- 28,
596
- ],
597
- [
598
- 0,
599
- 1,
600
- 3,
601
- 4,
602
- 6,
603
- 7,
604
- 8,
605
- 9,
606
- 10,
607
- 12,
608
- 13,
609
- 14,
610
- 15,
611
- 16,
612
- 17,
613
- 18,
614
- 20,
615
- 22,
616
- 24,
617
- 25,
618
- 26,
619
- 27,
620
- 28,
621
- ],
622
- ]
623
- if lut is None or lut < 1 or lut > 23:
624
- lut = 22
625
- self.cmap = discretemap(self.cname, [clrs[i] for i in indexes[lut - 1]])
626
- if lut == 23:
627
- self.cmap.set_bad("#777777")
628
- else:
629
- self.cmap.set_bad("#FFFFFF")
630
-
631
- def show(self) -> None:
632
- """
633
- List names of defined colormaps.
634
- """
635
- print(" ".join(repr(n) for n in self.namelist))
636
-
637
- def get(
638
- self, cname: str = "rainbow_PuRd", lut: int | None = None
639
- ) -> LinearSegmentedColormap:
640
- """
641
- Return requested colormap, default is 'rainbow_PuRd'.
642
- """
643
- self.cname = cname
644
- if cname == "rainbow_discrete":
645
- self.__rainbow_discrete(lut)
646
- else:
647
- self.funcdict[cname]() # type: ignore
648
- return self.cmap
649
-
650
-
651
- def tol_cmap(
652
- colormap: str | None = None, lut: int | None = None
653
- ) -> Sequence[str] | LinearSegmentedColormap:
654
- """
655
- Continuous and discrete color sets for ordered data.
656
-
657
- Return a matplotlib colormap.
658
- Parameter lut is ignored for all colormaps except 'rainbow_discrete'.
659
- """
660
- obj = TOLcmaps()
661
- if colormap is None:
662
- return obj.namelist
663
- if colormap not in obj.namelist:
664
- colormap = "rainbow_PuRd"
665
- print(
666
- "*** Warning: requested colormap not defined,",
667
- "known colormaps are {}.".format(obj.namelist), # noqa: UP032
668
- "Using {}.".format(colormap), # noqa: UP032
669
- )
670
- return obj.get(colormap, lut)
671
-
672
-
673
- Bcset = namedtuple("Bcset", "blue red green yellow cyan purple grey black")
674
- Hcset = namedtuple("Hcset", "blue yellow red black")
675
- Vcset = namedtuple("Vcset", "orange blue cyan magenta red teal grey black")
676
- Muset = namedtuple(
677
- "Muset", "rose indigo sand green cyan wine teal olive purple pale_grey black"
678
- )
679
- Mcset = namedtuple(
680
- "Mcset", "light_blue dark_blue light_yellow dark_red dark_yellow light_red black"
681
- )
682
- Lcset = namedtuple(
683
- "Lcset",
684
- "light_blue orange light_yellow pink light_cyan mint pear olive pale_grey black",
685
- )
686
-
687
-
688
- def tol_cset( # noqa: PLR0911
689
- colorset: str | None = None,
690
- ) -> Sequence[str] | Bcset | Hcset | Vcset | Muset | Mcset | Lcset:
691
- """
692
- Discrete color sets for qualitative data.
693
-
694
- Define a namedtuple instance with the colors.
695
- Examples for: cset = tol_cset(<scheme>)
696
- - cset.red and cset[1] give the same color (in default 'bright' colorset)
697
- - cset._fields gives a tuple with all color names
698
- - list(cset) gives a list with all colors
699
- """
700
-
701
- namelist = (
702
- "bright",
703
- "high-contrast",
704
- "vibrant",
705
- "muted",
706
- "medium-contrast",
707
- "light",
708
- )
709
-
710
- Bcinst = Bcset(
711
- "#4477AA",
712
- "#EE6677",
713
- "#228833",
714
- "#CCBB44",
715
- "#66CCEE",
716
- "#AA3377",
717
- "#BBBBBB",
718
- "#000000",
719
- )
720
-
721
- if colorset is None:
722
- return namelist
723
-
724
- elif colorset == "bright":
725
- return Bcinst
726
-
727
- elif colorset == "high-contrast":
728
- return Hcset("#004488", "#DDAA33", "#BB5566", "#000000")
729
-
730
- elif colorset == "vibrant":
731
- return Vcset(
732
- "#EE7733",
733
- "#0077BB",
734
- "#33BBEE",
735
- "#EE3377",
736
- "#CC3311",
737
- "#009988",
738
- "#BBBBBB",
739
- "#000000",
740
- )
741
-
742
- elif colorset == "muted":
743
- return Muset(
744
- "#CC6677",
745
- "#332288",
746
- "#DDCC77",
747
- "#117733",
748
- "#88CCEE",
749
- "#882255",
750
- "#44AA99",
751
- "#999933",
752
- "#AA4499",
753
- "#DDDDDD",
754
- "#000000",
755
- )
756
-
757
- elif colorset == "medium-contrast":
758
- return Mcset(
759
- "#6699CC", "#004488", "#EECC66", "#994455", "#997700", "#EE99AA", "#000000"
760
- )
761
-
762
- elif colorset == "light":
763
- return Lcset(
764
- "#77AADD",
765
- "#EE8866",
766
- "#EEDD88",
767
- "#FFAABB",
768
- "#99DDFF",
769
- "#44BB99",
770
- "#BBCC33",
771
- "#AAAA00",
772
- "#DDDDDD",
773
- "#000000",
774
- )
775
- else:
776
- colorset = "bright"
777
- print(
778
- "*** Warning: requested colorset not defined,",
779
- "known colorsets are {}.".format(namelist), # noqa: UP032
780
- "Using {}.".format(colorset), # noqa: UP032
781
- )
782
- return Bcinst
783
-
784
-
785
- def main() -> None:
786
- from matplotlib import pyplot as plt
787
-
788
- # Change default colorset (for lines) and colormap (for maps).
789
- # plt.rc('axes', prop_cycle=plt.cycler('color', list(tol_cset('bright'))))
790
- # plt.cm.register_cmap('rainbow_PuRd', tol_cmap('rainbow_PuRd'))
791
- # plt.rc('image', cmap='rainbow_PuRd')
792
- # Show colorsets tol_cset(<scheme>).
793
- schemes: Sequence[str] = tol_cset()
794
- fig, axes = plt.subplots(ncols=len(schemes), figsize=(9, 3))
795
- fig.subplots_adjust(top=0.9, bottom=0.02, left=0.02, right=0.92)
796
- for ax, scheme in zip(axes, schemes): # type: ignore
797
- cset = tol_cset(scheme)
798
- names = cset._fields # type: ignore
799
- colors = list(cset)
800
- for name, color in zip(names, colors):
801
- ax.scatter([], [], c=color, s=80, label=name)
802
- ax.set_axis_off()
803
- ax.legend(loc=2)
804
- ax.set_title(scheme)
805
- plt.show()
806
-
807
- # Show colormaps tol_cmap(<scheme>).
808
- schemes: Sequence[str] = tol_cmap() # type: ignore
809
- gradient = np.linspace(0, 1, 256)
810
- gradient = np.vstack((gradient, gradient))
811
- fig, axes = plt.subplots(nrows=len(schemes))
812
- fig.subplots_adjust(top=0.98, bottom=0.02, left=0.2, right=0.99)
813
- for ax, scheme in zip(axes, schemes): # type: ignore
814
- pos = list(ax.get_position().bounds)
815
- ax.set_axis_off()
816
- ax.imshow(gradient, aspect=4, cmap=tol_cmap(scheme))
817
- fig.text(
818
- pos[0] - 0.01,
819
- pos[1] + pos[3] / 2.0,
820
- scheme,
821
- va="center",
822
- ha="right",
823
- fontsize=10,
824
- )
825
- plt.show()
826
-
827
- # Show colormaps tol_cmap('rainbow_discrete', <lut>).
828
- gradient = np.linspace(0, 1, 256)
829
- gradient = np.vstack((gradient, gradient))
830
- fig, axes = plt.subplots(nrows=23)
831
- fig.subplots_adjust(top=0.98, bottom=0.02, left=0.25, right=0.99)
832
- for lut, ax in enumerate(axes, start=1): # type: ignore
833
- pos = list(ax.get_position().bounds)
834
- ax.set_axis_off()
835
- ax.imshow(gradient, aspect=4, cmap=tol_cmap("rainbow_discrete", lut))
836
- fig.text(
837
- pos[0] - 0.01,
838
- pos[1] + pos[3] / 2.0,
839
- "rainbow_discrete, " + str(lut),
840
- va="center",
841
- ha="right",
842
- fontsize=10,
843
- )
844
- plt.show()
845
-
846
-
847
- if __name__ == "__main__":
848
- main()