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