Skip to content

Commit a75ca65

Browse files
plotnine and seaborn
1 parent 700ee8e commit a75ca65

File tree

2 files changed

+50
-16
lines changed

2 files changed

+50
-16
lines changed

quarto/__init__.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
from quarto.quarto import path
77
from quarto.render import render
88
from quarto.metadata import metadata
9-
from quarto.theme import plotly_theme_colors, plotly_theme_brand, \
10-
altair_theme_colors, altair_theme_brand, \
9+
from quarto.theme import altair_theme_colors, altair_theme_brand, \
1110
bokeh_theme_colors, bokeh_theme_brand, \
1211
great_tables_theme_colors, great_tables_theme_brand, \
13-
matplotlib_theme_colors, matplotlib_theme_brand
12+
matplotlib_theme_colors, matplotlib_theme_brand, \
13+
plotnine_theme_colors, plotnine_theme_brand, \
14+
plotly_theme_colors, plotly_theme_brand, \
15+
seaborn_theme_colors, seaborn_theme_brand

quarto/theme.py

Lines changed: 45 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,6 @@
11
import yaml
22
from functools import partial
33

4-
def plotly_theme_colors(bg, fg):
5-
import plotly.graph_objects as go
6-
return go.layout.Template({'layout': {
7-
'paper_bgcolor': bg,
8-
'plot_bgcolor': bg,
9-
'font_color': fg,
10-
}})
11-
12-
def plotly_theme_brand(brand_yml):
13-
brand = yaml.safe_load(open(brand_yml).read())
14-
return plotly_theme_colors(brand["color"]["background"], brand["color"]["foreground"])
15-
16-
174
def altair_theme_colors(bg, fg):
185
return {
196
'config': {
@@ -99,3 +86,48 @@ def matplotlib_theme_brand(brand_yml):
9986
brand["color"]["foreground"],
10087
brand["color"]["primary"],
10188
)
89+
90+
91+
def plotnine_theme_colors(bg, fg):
92+
from plotnine import theme, element_rect, element_text
93+
return theme(
94+
plot_background=element_rect(fill=bg, size=0),
95+
text=element_text(color=fg)
96+
)
97+
98+
def plotnine_theme_brand(brand_yml):
99+
brand = yaml.safe_load(open(brand_yml).read())
100+
return plotnine_theme_colors(brand["color"]["background"], brand["color"]["foreground"])
101+
102+
103+
def plotly_theme_colors(bg, fg):
104+
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+
}})
110+
111+
def plotly_theme_brand(brand_yml):
112+
brand = yaml.safe_load(open(brand_yml).read())
113+
return plotly_theme_colors(brand["color"]["background"], brand["color"]["foreground"])
114+
115+
116+
def seaborn_theme_colors(bg, fg):
117+
# seaborn accepts matplotlib rcparams
118+
return {
119+
"axes.facecolor": bg,
120+
"axes.edgecolor": fg,
121+
"axes.labelcolor": fg,
122+
"axes.titlecolor": fg,
123+
"figure.facecolor": bg,
124+
"figure.edgecolor": fg,
125+
"text.color": fg,
126+
"xtick.color": fg,
127+
"ytick.color": fg,
128+
"grid.color": fg,
129+
}
130+
131+
def seaborn_theme_brand(brand_yml):
132+
brand = yaml.safe_load(open(brand_yml).read())
133+
return seaborn_theme_colors(brand["color"]["background"], brand["color"]["foreground"])

0 commit comments

Comments
 (0)