You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
By default, PyWry applies the built-in `plotly_dark` or `plotly_white` template based on the current theme. To customize chart colors *per theme* while preserving automatic switching, use `template_dark` and `template_light` on `PlotlyConfig`:
212
+
213
+
```python
214
+
from pywry import PlotlyConfig
215
+
216
+
config = PlotlyConfig(
217
+
template_dark={
218
+
"layout": {
219
+
"paper_bgcolor": "#1a1a2e",
220
+
"plot_bgcolor": "#16213e",
221
+
"font": {"color": "#e0e0e0"},
222
+
}
223
+
},
224
+
template_light={
225
+
"layout": {
226
+
"paper_bgcolor": "#ffffff",
227
+
"plot_bgcolor": "#f0f0f0",
228
+
"font": {"color": "#222222"},
229
+
}
230
+
},
231
+
)
232
+
233
+
handle = app.show_plotly(fig, config=config)
234
+
```
235
+
236
+
**How it works:**
237
+
238
+
- Your overrides are **deep-merged** on top of the built-in base template (`plotly_dark` or `plotly_white`).
239
+
-**User values always win** on conflict. Anything you don't set is inherited from the base.
240
+
- Both templates are stored on the chart and automatically selected when the theme toggles.
241
+
- Arrays (e.g., colorways) are replaced entirely, not element-merged.
242
+
243
+
You can also set only one side — e.g., `template_dark` alone — and the other theme will use the unmodified base.
244
+
245
+
!!! tip
246
+
Use `template_dark` / `template_light` instead of setting `fig.update_layout(template=...)` directly. The latter gets overwritten on theme switch; the former survives toggles.
247
+
209
248
## Next Steps
210
249
211
250
-**[`PlotlyConfig` Reference](../reference/plotly-config.md)** — All configuration options
Copy file name to clipboardExpand all lines: pywry/docs/docs/guides/theming.md
+34-1Lines changed: 34 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -230,7 +230,40 @@ Target specific components by their `component_id`:
230
230
231
231
## Plotly Theming
232
232
233
-
PyWry automatically switches Plotly figures between `plotly_dark` and `plotly_white` templates when the theme changes. For custom Plotly styling, set layout properties on the figure:
233
+
PyWry automatically switches Plotly figures between `plotly_dark` and `plotly_white` templates when the theme changes.
234
+
235
+
### Custom Per-Theme Templates
236
+
237
+
To customize chart colors for each theme — while still getting automatic switching — use `template_dark` and `template_light` on `PlotlyConfig`:
238
+
239
+
```python
240
+
from pywry import PlotlyConfig
241
+
242
+
config = PlotlyConfig(
243
+
template_dark={
244
+
"layout": {
245
+
"paper_bgcolor": "#1a1a2e",
246
+
"plot_bgcolor": "#16213e",
247
+
"font": {"color": "#e0e0e0"},
248
+
}
249
+
},
250
+
template_light={
251
+
"layout": {
252
+
"paper_bgcolor": "#ffffff",
253
+
"plot_bgcolor": "#f0f0f0",
254
+
"font": {"color": "#222222"},
255
+
}
256
+
},
257
+
)
258
+
259
+
app.show_plotly(fig, config=config)
260
+
```
261
+
262
+
Your overrides are **deep-merged** on top of the built-in base template — user values always win, and anything you don't set is inherited from the base. Both templates are stored on the chart element and automatically selected when the theme toggles via `pywry:update-theme`.
263
+
264
+
### Transparent Backgrounds
265
+
266
+
For charts that should use the window background color directly:
0 commit comments