1
1
from functools import partial
2
- from brand_yml import Brand
2
+
3
3
4
4
def theme_colors_altair (bg , fg ):
5
5
return {
6
- ' config' : {
7
- ' view' : {' stroke' : ' transparent' },
8
- ' axis' : {
9
- ' domainColor' : fg ,
10
- ' labelColor' : fg ,
11
- ' titleColor' : fg ,
6
+ " config" : {
7
+ " view" : {" stroke" : " transparent" },
8
+ " axis" : {
9
+ " domainColor" : fg ,
10
+ " labelColor" : fg ,
11
+ " titleColor" : fg ,
12
12
},
13
- ' legend' : {
14
- ' labelColor' : fg ,
15
- ' titleColor' : fg ,
13
+ " legend" : {
14
+ " labelColor" : fg ,
15
+ " titleColor" : fg ,
16
16
},
17
- ' background' : bg , # Background color
17
+ " background" : bg , # Background color
18
18
}
19
19
}
20
20
21
+
21
22
def theme_brand_altair (brand_yml ):
22
- brand = Brand .from_yaml (brand_yml )
23
- bg = brand .color .background
24
- fg = brand .color .foreground
25
- return partial (theme_colors_altair , bg , fg )
23
+ from brand_yml import Brand
24
+
25
+ brand = Brand .from_yaml (brand_yml )
26
+ bg = brand .color .background
27
+ fg = brand .color .foreground
28
+ return partial (theme_colors_altair , bg , fg )
29
+
26
30
27
31
# background fill is incomplete
28
32
def theme_colors_bokeh (bg , fg ):
29
33
from bokeh .io import curdoc
30
34
from bokeh .themes import Theme
31
- curdoc ().theme = Theme (json = {'attrs' : {
32
- 'figure' : {
33
- 'background_fill_color' : bg , # just plot area
34
- },
35
- 'Title' : {
36
- 'background_fill_color' : bg ,
37
- 'text_color' : fg ,
38
- },
39
- 'Axis' : {
40
- 'background_fill_color' : bg ,
41
- 'axis_label_text_color' : fg ,
42
- 'major_label_text_color' : fg ,
43
- },
44
- }})
35
+
36
+ curdoc ().theme = Theme (
37
+ json = {
38
+ "attrs" : {
39
+ "figure" : {
40
+ "background_fill_color" : bg , # just plot area
41
+ },
42
+ "Title" : {
43
+ "background_fill_color" : bg ,
44
+ "text_color" : fg ,
45
+ },
46
+ "Axis" : {
47
+ "background_fill_color" : bg ,
48
+ "axis_label_text_color" : fg ,
49
+ "major_label_text_color" : fg ,
50
+ },
51
+ }
52
+ }
53
+ )
54
+
45
55
46
56
def theme_brand_bokeh (brand_yml ):
57
+ from brand_yml import Brand
58
+
47
59
brand = Brand .from_yaml (brand_yml )
48
60
fg = brand .color .foreground
49
61
bg = brand .color .background
50
62
return partial (theme_colors_bokeh , bg , fg )
51
63
52
64
53
65
def theme_colors_great_tables (bg , fg ):
54
- return {
55
- 'table_background_color' : bg ,
56
- 'table_font_color' : fg
57
- }
66
+ return {"table_background_color" : bg , "table_font_color" : fg }
67
+
68
+
58
69
def theme_brand_great_tables (brand_yml ):
70
+ from brand_yml import Brand
71
+
59
72
brand = Brand .from_yaml (brand_yml )
60
73
fg = brand .color .foreground
61
74
bg = brand .color .background
@@ -65,6 +78,7 @@ def theme_brand_great_tables(brand_yml):
65
78
def theme_colors_matplotlib (bg , fg , primary ):
66
79
import matplotlib as mpl
67
80
from cycler import cycler
81
+
68
82
mpl .rcParams ["axes.facecolor" ] = bg
69
83
mpl .rcParams ["axes.edgecolor" ] = fg
70
84
mpl .rcParams ["axes.labelcolor" ] = fg
@@ -75,10 +89,12 @@ def theme_colors_matplotlib(bg, fg, primary):
75
89
mpl .rcParams ["xtick.color" ] = fg
76
90
mpl .rcParams ["ytick.color" ] = fg
77
91
if primary :
78
- mpl .rcParams ["axes.prop_cycle" ] = cycler (' color' , [primary ])
92
+ mpl .rcParams ["axes.prop_cycle" ] = cycler (" color" , [primary ])
79
93
80
94
81
95
def theme_brand_matplotlib (brand_yml ):
96
+ from brand_yml import Brand
97
+
82
98
brand = Brand .from_yaml (brand_yml )
83
99
return partial (
84
100
theme_colors_matplotlib ,
@@ -90,43 +106,59 @@ def theme_brand_matplotlib(brand_yml):
90
106
91
107
def theme_colors_plotnine (bg , fg ):
92
108
from plotnine import theme , element_rect , element_text
109
+
93
110
return theme (
94
- plot_background = element_rect (fill = bg , size = 0 ),
95
- text = element_text (color = fg )
111
+ plot_background = element_rect (fill = bg , size = 0 ), text = element_text (color = fg )
96
112
)
97
113
114
+
98
115
def theme_brand_plotnine (brand_yml ):
116
+ from brand_yml import Brand
117
+
99
118
brand = Brand .from_yaml (brand_yml )
100
119
return theme_colors_plotnine (brand .color .background , brand .color .foreground )
101
120
102
121
103
122
def theme_colors_plotly (bg , fg ):
104
123
import plotly .graph_objects as go
105
- return go .layout .Template ({'layout' : {
106
- 'paper_bgcolor' : bg ,
107
- 'plot_bgcolor' : bg ,
108
- 'font_color' : fg ,
109
- }})
124
+
125
+ return go .layout .Template (
126
+ {
127
+ "layout" : {
128
+ "paper_bgcolor" : bg ,
129
+ "plot_bgcolor" : bg ,
130
+ "font_color" : fg ,
131
+ }
132
+ }
133
+ )
134
+
110
135
111
136
def theme_brand_plotly (brand_yml ):
137
+ from brand_yml import Brand
138
+
112
139
brand = Brand .from_yaml (brand_yml )
113
140
return theme_colors_plotly (brand .color .background , brand .color .foreground )
114
141
115
142
116
143
def theme_colors_pygal (_bg , fg , primary , secondary ):
117
144
from pygal .style import Style
145
+
118
146
return Style (
119
- background = ' transparent' ,
120
- plot_background = ' transparent' ,
147
+ background = " transparent" ,
148
+ plot_background = " transparent" ,
121
149
foreground = fg ,
122
150
foreground_strong = primary ,
123
- foreground_subtle = secondary or '#630C0D' ,
124
- opacity = '.6' ,
125
- opacity_hover = '.9' ,
126
- transition = '400ms ease-in' ,
127
- colors = ('#E853A0' , '#E8537A' , '#E95355' , '#E87653' , '#E89B53' ))
151
+ foreground_subtle = secondary or "#630C0D" ,
152
+ opacity = ".6" ,
153
+ opacity_hover = ".9" ,
154
+ transition = "400ms ease-in" ,
155
+ colors = ("#E853A0" , "#E8537A" , "#E95355" , "#E87653" , "#E89B53" ),
156
+ )
157
+
128
158
129
159
def theme_brand_pygal (brand_yml ):
160
+ from brand_yml import Brand
161
+
130
162
brand = Brand .from_yaml (brand_yml )
131
163
return theme_colors_pygal (
132
164
brand .color .background ,
@@ -139,18 +171,21 @@ def theme_brand_pygal(brand_yml):
139
171
def theme_colors_seaborn (bg , fg ):
140
172
# seaborn accepts matplotlib rcparams
141
173
return {
142
- "axes.facecolor" : bg ,
143
- "axes.edgecolor" : fg ,
144
- "axes.labelcolor" : fg ,
145
- "axes.titlecolor" : fg ,
146
- "figure.facecolor" : bg ,
147
- "figure.edgecolor" : fg ,
148
- "text.color" : fg ,
149
- "xtick.color" : fg ,
150
- "ytick.color" : fg ,
151
- "grid.color" : fg ,
174
+ "axes.facecolor" : bg ,
175
+ "axes.edgecolor" : fg ,
176
+ "axes.labelcolor" : fg ,
177
+ "axes.titlecolor" : fg ,
178
+ "figure.facecolor" : bg ,
179
+ "figure.edgecolor" : fg ,
180
+ "text.color" : fg ,
181
+ "xtick.color" : fg ,
182
+ "ytick.color" : fg ,
183
+ "grid.color" : fg ,
152
184
}
153
185
186
+
154
187
def theme_brand_seaborn (brand_yml ):
155
- brand = Brand .from_yaml (brand_yml )
156
- return theme_colors_seaborn (brand .color .background , brand .color .foreground )
188
+ from brand_yml import Brand
189
+
190
+ brand = Brand .from_yaml (brand_yml )
191
+ return theme_colors_seaborn (brand .color .background , brand .color .foreground )
0 commit comments