statworx_theme 2.0.2__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.
- statworx_theme/__init__.py +16 -0
- statworx_theme/colormaps.py +95 -0
- statworx_theme/colors.py +60 -0
- statworx_theme/py.typed +0 -0
- statworx_theme/styles/statworx.mplstyle +872 -0
- statworx_theme/utils.py +407 -0
- statworx_theme-2.0.2.dist-info/LICENSE +21 -0
- statworx_theme-2.0.2.dist-info/METADATA +141 -0
- statworx_theme-2.0.2.dist-info/RECORD +10 -0
- statworx_theme-2.0.2.dist-info/WHEEL +4 -0
statworx_theme/utils.py
ADDED
|
@@ -0,0 +1,407 @@
|
|
|
1
|
+
"""Utility functions for the statworx theme."""
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
import warnings
|
|
5
|
+
from os.path import dirname, join
|
|
6
|
+
|
|
7
|
+
# get path to config files
|
|
8
|
+
from shutil import copy
|
|
9
|
+
from typing import Any
|
|
10
|
+
|
|
11
|
+
import matplotlib as mpl
|
|
12
|
+
import matplotlib.pyplot as plt
|
|
13
|
+
from cycler import Cycler
|
|
14
|
+
from matplotlib.colors import LinearSegmentedColormap, ListedColormap
|
|
15
|
+
from matplotlib.style.core import reload_library
|
|
16
|
+
from seaborn.palettes import MPL_QUAL_PALS
|
|
17
|
+
|
|
18
|
+
import statworx_theme
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def register_listed_cmap(colors: list[str], name: str) -> ListedColormap:
|
|
22
|
+
"""Register a listed colormap in matplotlib.
|
|
23
|
+
|
|
24
|
+
Args:
|
|
25
|
+
colors: Color of the colormap
|
|
26
|
+
name: Name of the colormap
|
|
27
|
+
|
|
28
|
+
Returns:
|
|
29
|
+
Registered Colormap
|
|
30
|
+
"""
|
|
31
|
+
# register color map
|
|
32
|
+
cmap = ListedColormap(colors, N=len(colors), name=name)
|
|
33
|
+
with warnings.catch_warnings():
|
|
34
|
+
warnings.simplefilter("ignore")
|
|
35
|
+
mpl.colormaps.register(cmap=cmap, name=name)
|
|
36
|
+
|
|
37
|
+
# dark magic shit
|
|
38
|
+
MPL_QUAL_PALS.update({name: len(colors)})
|
|
39
|
+
return cmap
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def register_blended_cmap(colors: list[str], name: str) -> LinearSegmentedColormap:
|
|
43
|
+
"""Register a blended colormap to matplotlib.
|
|
44
|
+
|
|
45
|
+
Args:
|
|
46
|
+
colors: Colors of the colormap
|
|
47
|
+
name: Name of the colormap
|
|
48
|
+
|
|
49
|
+
Returns:
|
|
50
|
+
Registered Colormap
|
|
51
|
+
"""
|
|
52
|
+
cmap = LinearSegmentedColormap.from_list(name, colors)
|
|
53
|
+
with warnings.catch_warnings():
|
|
54
|
+
warnings.simplefilter("ignore")
|
|
55
|
+
mpl.colormaps.register(cmap=cmap, name=name)
|
|
56
|
+
return cmap
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def _install_styles() -> None:
|
|
60
|
+
"""Install matplotlib style files with suffix `.mplstyle` to the matplotlib config dir."""
|
|
61
|
+
# list all theme files
|
|
62
|
+
config_path = join(dirname(statworx_theme.__file__), "styles")
|
|
63
|
+
theme_files = [join(config_path, f) for f in os.listdir(config_path)]
|
|
64
|
+
|
|
65
|
+
# get config directory
|
|
66
|
+
config_dir = mpl.get_configdir()
|
|
67
|
+
style_dir = join(config_dir, "stylelib")
|
|
68
|
+
os.makedirs(style_dir, exist_ok=True)
|
|
69
|
+
|
|
70
|
+
# copy theme files into config directory
|
|
71
|
+
for file in theme_files:
|
|
72
|
+
copy(file, style_dir)
|
|
73
|
+
|
|
74
|
+
# reload matplotlib
|
|
75
|
+
reload_library()
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def apply_style() -> None:
|
|
79
|
+
"""Apply the statworx color style."""
|
|
80
|
+
_install_styles()
|
|
81
|
+
plt.style.use("statworx")
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def apply_custom_colors(colors: list[str], cmap_name: str = "stwx:custom", **kwargs: Any) -> None:
|
|
85
|
+
"""Apply custom custom colors to statworx style.
|
|
86
|
+
|
|
87
|
+
Args:
|
|
88
|
+
colors: List of custom colors as hex codes
|
|
89
|
+
cmap_name: Custom name of new colormap. Defaults to "stwx:custom".
|
|
90
|
+
**kwargs: Addition parameters that are passed to the style config
|
|
91
|
+
"""
|
|
92
|
+
# apply statworx style
|
|
93
|
+
apply_style()
|
|
94
|
+
|
|
95
|
+
# add colors as a custom cmap
|
|
96
|
+
register_listed_cmap(colors, cmap_name)
|
|
97
|
+
|
|
98
|
+
# add colors to current style
|
|
99
|
+
color_list = [{"color": c} for c in colors]
|
|
100
|
+
mpl.rcParams["axes.prop_cycle"] = Cycler(color_list)
|
|
101
|
+
|
|
102
|
+
# apply kwargs
|
|
103
|
+
mpl.rcParams.update(kwargs)
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def get_stwx_cmaps(as_hex: bool = True) -> dict[str, Any]:
|
|
107
|
+
"""Gets the registered colormaps as hex or cmap.
|
|
108
|
+
|
|
109
|
+
Args:
|
|
110
|
+
as_hex (bool, optional): Should the cmaps be returned as hexadecimal list or as a cmap.
|
|
111
|
+
Defaults to True.
|
|
112
|
+
|
|
113
|
+
Returns:
|
|
114
|
+
dict[str, Any]: The colormap name as a key and the hex-list or cmap as value.
|
|
115
|
+
"""
|
|
116
|
+
cmap_names = [cmap for cmap in plt.colormaps() if cmap.startswith("stwx:")]
|
|
117
|
+
cmaps = [plt.get_cmap(cmap) for cmap in cmap_names]
|
|
118
|
+
if as_hex:
|
|
119
|
+
cmap_hex_codes = [[mpl.colors.to_hex(cmap(i)) for i in range(cmap.N)] for cmap in cmaps]
|
|
120
|
+
return dict(zip(cmap_names, cmap_hex_codes))
|
|
121
|
+
return dict(zip(cmap_names, cmaps))
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def apply_style_altair(n_groups_ordinal: int = 10) -> None:
|
|
125
|
+
"""Apply the statworx color style for Altair.
|
|
126
|
+
|
|
127
|
+
Args:
|
|
128
|
+
n_groups_ordinal (int): The number of groups to be plotted for the ordinal
|
|
129
|
+
color map. Defaults to 10.
|
|
130
|
+
"""
|
|
131
|
+
import altair as alt # type: ignore
|
|
132
|
+
|
|
133
|
+
apply_style()
|
|
134
|
+
|
|
135
|
+
stwx_cmaps = get_stwx_cmaps()
|
|
136
|
+
|
|
137
|
+
_create_altair_theme(
|
|
138
|
+
primary=stwx_cmaps["stwx:alternative"][0],
|
|
139
|
+
category=stwx_cmaps["stwx:alternative"],
|
|
140
|
+
diverging=stwx_cmaps["stwx:BlRd_diverging"],
|
|
141
|
+
heatmap=stwx_cmaps["stwx:BlRd_diverging"],
|
|
142
|
+
ramp=stwx_cmaps["stwx:Bl_rise"],
|
|
143
|
+
ordinal=_shrink_cmap(stwx_cmaps["stwx:bad2good"], n_groups=n_groups_ordinal),
|
|
144
|
+
name="statworx_altair_theme",
|
|
145
|
+
)
|
|
146
|
+
|
|
147
|
+
alt.themes.enable("statworx_altair_theme")
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
def _shrink_cmap(cmap: list[str], n_groups: int) -> list[str]:
|
|
151
|
+
"""Shrinks the cmap for a fixed number of groups.
|
|
152
|
+
|
|
153
|
+
Args:
|
|
154
|
+
cmap (list[str]): The colormap.
|
|
155
|
+
n_groups (int): The number of groups in the data to plot.
|
|
156
|
+
|
|
157
|
+
Returns:
|
|
158
|
+
list[str]: Shrunken cmap.
|
|
159
|
+
"""
|
|
160
|
+
nth_element_to_keep = int(len(cmap) / n_groups)
|
|
161
|
+
return cmap[::nth_element_to_keep]
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
def _create_altair_theme(
|
|
165
|
+
primary: str,
|
|
166
|
+
category: list[str],
|
|
167
|
+
diverging: list[str],
|
|
168
|
+
heatmap: list[str],
|
|
169
|
+
ramp: list[str],
|
|
170
|
+
ordinal: list[str],
|
|
171
|
+
name: str,
|
|
172
|
+
) -> None:
|
|
173
|
+
"""Creates the altair theme and registers it.
|
|
174
|
+
|
|
175
|
+
Args:
|
|
176
|
+
primary (str): The primary color as hexadecimal string (e.g. "#d9d9d9").
|
|
177
|
+
category (list[str]): Categorical colors as list of hexadecimal strings.
|
|
178
|
+
diverging (list[str]): Diverging color palette as list of hexadecimal strings.
|
|
179
|
+
heatmap (list[str]): Heatmap color palette as list of hexadecimal strings.
|
|
180
|
+
ramp (list[str]): Ramp color palette as list of hexadecimal strings.
|
|
181
|
+
ordinal (list[str]): Ordinal color palette as list of hexadecimal strings.
|
|
182
|
+
name (str): The name of the theme.
|
|
183
|
+
"""
|
|
184
|
+
import altair as alt
|
|
185
|
+
|
|
186
|
+
def statworx_altair_theme() -> dict:
|
|
187
|
+
"""STATWORX altair theme.
|
|
188
|
+
|
|
189
|
+
Returns:
|
|
190
|
+
altair theme
|
|
191
|
+
"""
|
|
192
|
+
font = "Arial"
|
|
193
|
+
primary_color = primary
|
|
194
|
+
font_color = "#000000"
|
|
195
|
+
grey_color = "#d9d9d9"
|
|
196
|
+
base_size = 20
|
|
197
|
+
lg_font = base_size * 1.25
|
|
198
|
+
sm_font = base_size * 0.8
|
|
199
|
+
# xl_font = base_size * 1.75
|
|
200
|
+
config = {
|
|
201
|
+
"config": {
|
|
202
|
+
"view": {
|
|
203
|
+
"stroke": False,
|
|
204
|
+
},
|
|
205
|
+
"background": "white", # None for transparent
|
|
206
|
+
"arc": {"fill": primary_color},
|
|
207
|
+
"area": {"fill": primary_color},
|
|
208
|
+
"bar": {"fill": primary_color},
|
|
209
|
+
"boxplot": {"fill": primary_color},
|
|
210
|
+
"circle": {"fill": primary_color},
|
|
211
|
+
"line": {"stroke": primary_color},
|
|
212
|
+
"mark": {"tooltip": True},
|
|
213
|
+
"path": {"stroke": primary_color},
|
|
214
|
+
"point": {"stroke": primary_color},
|
|
215
|
+
"rect": {"fill": primary_color},
|
|
216
|
+
"rule": {"fill": primary_color},
|
|
217
|
+
"shape": {"stroke": primary_color},
|
|
218
|
+
"square": {"stroke": primary_color},
|
|
219
|
+
"symbol": {"fill": primary_color},
|
|
220
|
+
"title": {
|
|
221
|
+
"font": font,
|
|
222
|
+
"color": font_color,
|
|
223
|
+
"fontSize": lg_font,
|
|
224
|
+
"anchor": "start",
|
|
225
|
+
"offset": 10,
|
|
226
|
+
},
|
|
227
|
+
"axis": {
|
|
228
|
+
"titleFont": font,
|
|
229
|
+
"titleColor": font_color,
|
|
230
|
+
"titleFontSize": sm_font,
|
|
231
|
+
"labelFont": font,
|
|
232
|
+
"labelColor": font_color,
|
|
233
|
+
"labelFontSize": sm_font,
|
|
234
|
+
"gridColor": grey_color,
|
|
235
|
+
"domainColor": font_color,
|
|
236
|
+
"tickColor": "#fff",
|
|
237
|
+
"labelPadding": 10,
|
|
238
|
+
"titlePadding": 10,
|
|
239
|
+
"ticks": False,
|
|
240
|
+
"domain": False,
|
|
241
|
+
# "offset": 10
|
|
242
|
+
},
|
|
243
|
+
"header": {
|
|
244
|
+
"labelFont": font,
|
|
245
|
+
"titleFont": font,
|
|
246
|
+
"labelFontSize": base_size,
|
|
247
|
+
"titleFontSize": base_size,
|
|
248
|
+
},
|
|
249
|
+
"legend": {
|
|
250
|
+
"titleFont": font,
|
|
251
|
+
"titleColor": font_color,
|
|
252
|
+
"titleFontSize": sm_font,
|
|
253
|
+
"labelFont": font,
|
|
254
|
+
"labelColor": font_color,
|
|
255
|
+
"labelFontSize": sm_font,
|
|
256
|
+
},
|
|
257
|
+
"range": {
|
|
258
|
+
"category": category,
|
|
259
|
+
"diverging": diverging,
|
|
260
|
+
"heatmap": heatmap,
|
|
261
|
+
"ramp": ramp,
|
|
262
|
+
"ordinal": ordinal,
|
|
263
|
+
},
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
return config
|
|
267
|
+
|
|
268
|
+
alt.themes.register(
|
|
269
|
+
name,
|
|
270
|
+
statworx_altair_theme,
|
|
271
|
+
)
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
def apply_custom_colors_altair(
|
|
275
|
+
primary: str | None = None,
|
|
276
|
+
category: list[str] | None = None,
|
|
277
|
+
diverging: list[str] | None = None,
|
|
278
|
+
heatmap: list[str] | None = None,
|
|
279
|
+
ramp: list[str] | None = None,
|
|
280
|
+
ordinal: list[str] | None = None,
|
|
281
|
+
n_groups_ordinal: int = 10,
|
|
282
|
+
) -> None:
|
|
283
|
+
"""Applies a custom altair theme with custom color palettes to the statworx style.
|
|
284
|
+
|
|
285
|
+
Args:
|
|
286
|
+
primary (str, optional): The primary color as hexadecimal string (e.g. "#d9d9d9").
|
|
287
|
+
Defaults to None (statworx style is kept).
|
|
288
|
+
category (list[str], optional): Categorical colors as list of hexadecimal strings.
|
|
289
|
+
Defaults to None (statworx style is kept).
|
|
290
|
+
diverging (list[str], optional): Diverging color palette as list of hexadecimal strings.
|
|
291
|
+
Defaults to None (statworx style is kept).
|
|
292
|
+
heatmap (list[str], optional): Heatmap color palette as list of hexadecimal strings.
|
|
293
|
+
Defaults to None (statworx style is kept).
|
|
294
|
+
ramp (list[str], optional): Ramp color palette as list of hexadecimal strings.
|
|
295
|
+
Defaults to None (statworx style is kept).
|
|
296
|
+
ordinal (list[str], optional): Ordinal color palette as list of hexadecimal strings.
|
|
297
|
+
Defaults to None (statworx style is kept).
|
|
298
|
+
n_groups_ordinal (int): The number of groups to be plotted using the ordinal color map.
|
|
299
|
+
Defaults to 10.
|
|
300
|
+
"""
|
|
301
|
+
import altair as alt # type: ignore
|
|
302
|
+
|
|
303
|
+
stwx_cmaps = get_stwx_cmaps()
|
|
304
|
+
_create_altair_theme(
|
|
305
|
+
primary=stwx_cmaps["stwx:alternative"][0] if primary is None else primary,
|
|
306
|
+
category=stwx_cmaps["stwx:alternative"] if category is None else category,
|
|
307
|
+
diverging=stwx_cmaps["stwx:BlRd_diverging"] if diverging is None else diverging,
|
|
308
|
+
heatmap=stwx_cmaps["stwx:BlRd_diverging"] if heatmap is None else heatmap,
|
|
309
|
+
ramp=stwx_cmaps["stwx:BlRd_diverging"] if ramp is None else ramp,
|
|
310
|
+
ordinal=(
|
|
311
|
+
_shrink_cmap(stwx_cmaps["stwx:bad2good"], n_groups=n_groups_ordinal)
|
|
312
|
+
if ordinal is None
|
|
313
|
+
else _shrink_cmap(ordinal, n_groups=n_groups_ordinal)
|
|
314
|
+
),
|
|
315
|
+
name="custom_altair_theme",
|
|
316
|
+
)
|
|
317
|
+
|
|
318
|
+
alt.themes.enable("custom_altair_theme")
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
def apply_style_plotly() -> None:
|
|
322
|
+
"""Apply the statworx color style for plotly."""
|
|
323
|
+
import plotly.io as pio # type: ignore
|
|
324
|
+
|
|
325
|
+
apply_style()
|
|
326
|
+
|
|
327
|
+
stwx_cmaps = get_stwx_cmaps()
|
|
328
|
+
_create_plotly_theme(
|
|
329
|
+
category=stwx_cmaps["stwx:alternative"],
|
|
330
|
+
diverging=stwx_cmaps["stwx:BlRd_diverging"],
|
|
331
|
+
sequential=stwx_cmaps["stwx:bad2good"],
|
|
332
|
+
sequential_minus=stwx_cmaps["stwx:good2bad"],
|
|
333
|
+
heatmap=stwx_cmaps["stwx:BlRd_diverging"],
|
|
334
|
+
name="statworx_plotly_theme",
|
|
335
|
+
)
|
|
336
|
+
|
|
337
|
+
pio.templates.default = "statworx_plotly_theme"
|
|
338
|
+
|
|
339
|
+
|
|
340
|
+
def _create_plotly_theme(
|
|
341
|
+
category: list[str],
|
|
342
|
+
diverging: list[str],
|
|
343
|
+
sequential: list[str],
|
|
344
|
+
sequential_minus: list[str],
|
|
345
|
+
heatmap: list[str],
|
|
346
|
+
name: str,
|
|
347
|
+
):
|
|
348
|
+
"""Creates the plotly theme and registers it.
|
|
349
|
+
|
|
350
|
+
Args:
|
|
351
|
+
category (list[str]): Categorical colors as list of hexadecimal strings.
|
|
352
|
+
diverging (list[str]): Diverging color palette as list of hexadecimal strings.
|
|
353
|
+
sequential (list[str]): Sequential color palette as list of hexadecimal strings.
|
|
354
|
+
sequential_minus (list[str]): Downwards sequential color palette as list of hex strings.
|
|
355
|
+
heatmap (list[str]): Heatmap color palette as list of hexadecimal strings.
|
|
356
|
+
name (str): The name of the theme.
|
|
357
|
+
"""
|
|
358
|
+
import plotly.graph_objects as go
|
|
359
|
+
import plotly.io as pio
|
|
360
|
+
|
|
361
|
+
plotly_template = go.layout.Template(pio.templates["plotly_white"])
|
|
362
|
+
|
|
363
|
+
plotly_template.layout.colorway = category
|
|
364
|
+
plotly_template.layout.colorscale.diverging = diverging
|
|
365
|
+
plotly_template.layout.colorscale.sequential = sequential
|
|
366
|
+
plotly_template.layout.colorscale.sequentialminus = sequential_minus
|
|
367
|
+
plotly_template.data.heatmap[0].colorscale = heatmap
|
|
368
|
+
|
|
369
|
+
pio.templates[name] = go.layout.Template(plotly_template)
|
|
370
|
+
|
|
371
|
+
|
|
372
|
+
def apply_custom_colors_plotly(
|
|
373
|
+
category: list[str] | None = None,
|
|
374
|
+
diverging: list[str] | None = None,
|
|
375
|
+
sequential: list[str] | None = None,
|
|
376
|
+
sequential_minus: list[str] | None = None,
|
|
377
|
+
heatmap: list[str] | None = None,
|
|
378
|
+
):
|
|
379
|
+
"""Applies a custom plotly theme with custom color palettes to the statworx style.
|
|
380
|
+
|
|
381
|
+
Args:
|
|
382
|
+
category (list[str]): Categorical colors as list of hexadecimal strings.
|
|
383
|
+
Defaults to None (statworx style is kept).
|
|
384
|
+
diverging (list[str]): Diverging color palette as list of hexadecimal strings.
|
|
385
|
+
Defaults to None (statworx style is kept).
|
|
386
|
+
sequential (list[str]): Sequential color palette as list of hexadecimal strings.
|
|
387
|
+
Defaults to None (statworx style is kept).
|
|
388
|
+
sequential_minus (list[str]): Downwards sequential color palette as list of hex strings.
|
|
389
|
+
Defaults to None (statworx style is kept).
|
|
390
|
+
heatmap (list[str]): Heatmap color palette as list of hexadecimal strings.
|
|
391
|
+
Defaults to None (statworx style is kept).
|
|
392
|
+
"""
|
|
393
|
+
import plotly.io as pio
|
|
394
|
+
|
|
395
|
+
stwx_cmaps = get_stwx_cmaps()
|
|
396
|
+
_create_plotly_theme(
|
|
397
|
+
category=stwx_cmaps["stwx:alternative"] if category is None else category,
|
|
398
|
+
diverging=stwx_cmaps["stwx:BlRd_diverging"] if diverging is None else category,
|
|
399
|
+
sequential=stwx_cmaps["stwx:bad2good"] if sequential is None else sequential,
|
|
400
|
+
sequential_minus=(
|
|
401
|
+
stwx_cmaps["stwx:good2bad"] if sequential_minus is None else sequential_minus
|
|
402
|
+
),
|
|
403
|
+
heatmap=stwx_cmaps["stwx:BlRd_diverging"] if heatmap is None else heatmap,
|
|
404
|
+
name="custom_plotly_theme",
|
|
405
|
+
)
|
|
406
|
+
|
|
407
|
+
pio.templates.default = "custom_plotly_theme"
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 statworx GmbH
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: statworx_theme
|
|
3
|
+
Version: 2.0.2
|
|
4
|
+
Summary: A color theme for matplotlib using the offical statworx design
|
|
5
|
+
Home-page: https://statworx-theme.readthedocs.io/en/latest
|
|
6
|
+
License: MIT
|
|
7
|
+
Keywords: theme,matplotlib,plotting,statworx
|
|
8
|
+
Author: statworx Team
|
|
9
|
+
Author-email: accounts@statworx.com
|
|
10
|
+
Requires-Python: >=3.9,<4.0
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Provides-Extra: altair
|
|
18
|
+
Provides-Extra: plotly
|
|
19
|
+
Requires-Dist: altair (>=5.2.0) ; extra == "altair"
|
|
20
|
+
Requires-Dist: nbformat (>=5.4.0) ; extra == "plotly"
|
|
21
|
+
Requires-Dist: plotly (>=5.10.0) ; extra == "plotly"
|
|
22
|
+
Requires-Dist: seaborn (>=0.11.2)
|
|
23
|
+
Requires-Dist: statsmodels (>=0.13.0) ; extra == "plotly"
|
|
24
|
+
Requires-Dist: vega-datasets (>=0.9.0) ; extra == "altair"
|
|
25
|
+
Project-URL: Repository, https://github.com/STATWORX/statworx-theme
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
|
|
28
|
+
# Statworx Theme
|
|
29
|
+
|
|
30
|
+
[](https://badge.fury.io/py/statworx-theme)
|
|
31
|
+
[](https://statworx-theme.readthedocs.io/en/latest/?badge=latest)
|
|
32
|
+
[](https://github.com/STATWORX/statworx-theme/actions/workflows/release.yml)
|
|
33
|
+
[](https://github.com/STATWORX/statworx-theme/actions/workflows/conde_quality.yml)
|
|
34
|
+
[](https://pypi.org/project/kedro/)
|
|
35
|
+
[](https://github.com/STATWORX/statworx-theme/blob/master/LICENSE)
|
|
36
|
+

|
|
37
|
+
|
|
38
|
+
A color theme plugin for the [matplotlib](https://matplotlib.org/) library and all its derivatives, as well as an optional adaption of this theme for [altair](https://altair-viz.github.io/) and [plotly](https://plotly.com/python/), which automatically applies the official statworx color theme.
|
|
39
|
+
This package also registers commonly used [qualitative color maps](https://matplotlib.org/stable/tutorials/colors/colormaps.html) (such as a fade from good to bad) for use in presentations.
|
|
40
|
+
|
|
41
|
+

|
|
42
|
+
|
|
43
|
+
## Quick Start
|
|
44
|
+
|
|
45
|
+
Simply install a module with `pip` by using the following command.
|
|
46
|
+
|
|
47
|
+
```console
|
|
48
|
+
pip install statworx-theme
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
For usage of altair and plotly extra dependencies need to be installed using pip.
|
|
52
|
+
|
|
53
|
+
```console
|
|
54
|
+
pip install "statworx-theme[altair]"
|
|
55
|
+
pip install "statworx-theme[plotly]"
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
For using the styles inside a poetry managed project use `poetry add` with extras.
|
|
59
|
+
```console
|
|
60
|
+
#only matplotlib
|
|
61
|
+
poetry add statworx-theme
|
|
62
|
+
|
|
63
|
+
# altair theme
|
|
64
|
+
poetry add statworx-theme -E "altair"
|
|
65
|
+
|
|
66
|
+
# plotly theme
|
|
67
|
+
poetry add statworx-theme -E "plotly"
|
|
68
|
+
|
|
69
|
+
# Whole package
|
|
70
|
+
poetry add statworx-theme -E "altair plotly"
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
To apply the matplotlib style, you must call the `apply_style` function by typing:
|
|
75
|
+
|
|
76
|
+
```python
|
|
77
|
+
from statworx_theme import apply_style
|
|
78
|
+
apply_style()
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
For applying the plotly or altair style the respective `apply_style_<library>` function is used:
|
|
82
|
+
```python
|
|
83
|
+
from statworx_theme import apply_style_altair, apply_style_plotly
|
|
84
|
+
apply_style_altair()
|
|
85
|
+
apply_style_plotly()
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
## Gallery
|
|
90
|
+
|
|
91
|
+
#### Matplotlib
|
|
92
|
+
There is an extensive gallery of figures that use the Statworx theme that you can draw inspiration from. You can find it [here](https://statworx-theme.readthedocs.io/en/latest/gallery.html).
|
|
93
|
+
For a figure gallery using the altair and plotly theme see the respective notebooks inside the [repository](https://github.com/STATWORX/statworx-theme/tree/master/notebooks).
|
|
94
|
+
|
|
95
|
+

|
|
96
|
+
|
|
97
|
+
## Custom Colors
|
|
98
|
+
|
|
99
|
+
You can also use a custom list of color for the color scheme beside the official statworx colors.
|
|
100
|
+
There is a convenience function for that which is described below.
|
|
101
|
+
This simply changes the colors.
|
|
102
|
+
|
|
103
|
+
##### Matplotlib
|
|
104
|
+
In case you want to change the entire style you should implement your own `.mplstyle` file (see [this](https://matplotlib.org/stable/tutorials/introductory/customizing.html)).
|
|
105
|
+
|
|
106
|
+
```python
|
|
107
|
+
from statworx_theme import apply_custom_colors
|
|
108
|
+
|
|
109
|
+
custom_colors = [
|
|
110
|
+
DARK_BLUE := "#0A526B",
|
|
111
|
+
DARK_RED := "#6B0020",
|
|
112
|
+
GREY := "#808285",
|
|
113
|
+
]
|
|
114
|
+
apply_custom_colors(custom_colors)
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
#### Altair
|
|
118
|
+
|
|
119
|
+
```python
|
|
120
|
+
from statworx_theme import apply_custom_colors_altair
|
|
121
|
+
|
|
122
|
+
custom_colors = [
|
|
123
|
+
DARK_BLUE := "#0A526B",
|
|
124
|
+
DARK_RED := "#6B0020",
|
|
125
|
+
GREY := "#808285",
|
|
126
|
+
]
|
|
127
|
+
apply_custom_colors_altair(category=custom_colors)
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
#### Plotly
|
|
131
|
+
|
|
132
|
+
```python
|
|
133
|
+
from statworx_theme import apply_custom_colors_plotly
|
|
134
|
+
custom_colors = [
|
|
135
|
+
DARK_BLUE := "#0A526B",
|
|
136
|
+
DARK_RED := "#6B0020",
|
|
137
|
+
GREY := "#808285",
|
|
138
|
+
]
|
|
139
|
+
apply_custom_colors_plotly(category=custom_colors)
|
|
140
|
+
```
|
|
141
|
+
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
statworx_theme/__init__.py,sha256=BOwY6YtHaSMy91G5OgIuotAv65LMcARwQ3uIo1fgA2A,342
|
|
2
|
+
statworx_theme/colormaps.py,sha256=deY57Qfe-P0nsrFC_EpVKEiYEsOOkB2L8DeC3vj8w5E,2566
|
|
3
|
+
statworx_theme/colors.py,sha256=QkmM3a55eeIdxDuhGQXlaSZppNkolYxRQ2m_wJoUhxA,909
|
|
4
|
+
statworx_theme/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
|
+
statworx_theme/styles/statworx.mplstyle,sha256=-QSZEsqWx8gFo0zJJYUfcqz4f4uKp44qIbcp1UXdKV4,44890
|
|
6
|
+
statworx_theme/utils.py,sha256=AV3ilyZW_IKKOKQRtj8k34bhlbq32UjRWwx384UDxa4,14376
|
|
7
|
+
statworx_theme-2.0.2.dist-info/LICENSE,sha256=W8Xr7I6xo1I_aW4-QR722mxOGyng9n4HOnRmogx87GE,1070
|
|
8
|
+
statworx_theme-2.0.2.dist-info/METADATA,sha256=hKB6Qp9mXRkYq3LdDLOdImdFl7hCDdViOJKDTtyMQrc,5099
|
|
9
|
+
statworx_theme-2.0.2.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
|
10
|
+
statworx_theme-2.0.2.dist-info/RECORD,,
|