Skip to content

Commit 31b9e48

Browse files
committed
Add a section on theming with Plotly templates to the getting started guide
1 parent c1e9759 commit 31b9e48

6 files changed

Lines changed: 53 additions & 0 deletions

File tree

cicd_utils/ridgeplot_examples/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ def load_basic() -> go.Figure:
1919
return main()
2020

2121

22+
def load_basic_dark() -> go.Figure:
23+
from ._basic_dark import main
24+
25+
return main()
26+
27+
2228
def load_basic_hist() -> go.Figure:
2329
from ._basic_hist import main
2430

@@ -45,6 +51,7 @@ def load_probly() -> go.Figure:
4551

4652
ALL_EXAMPLES: list[Example] = [
4753
Example("basic", load_basic),
54+
Example("basic_dark", load_basic_dark),
4855
Example("basic_hist", load_basic_hist),
4956
Example("lincoln_weather", load_lincoln_weather),
5057
Example("lincoln_weather_red_blue", load_lincoln_weather_red_blue),
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from __future__ import annotations
2+
3+
from typing import TYPE_CHECKING
4+
5+
if TYPE_CHECKING:
6+
import plotly.graph_objects as go
7+
8+
9+
def main() -> go.Figure:
10+
import numpy as np
11+
12+
from ridgeplot import ridgeplot
13+
14+
rng = np.random.default_rng(42)
15+
my_samples = [rng.normal(n, size=900) for n in range(6, 0, -2)]
16+
fig = ridgeplot(samples=my_samples, template="plotly_dark")
17+
fig.update_layout(height=400, width=800)
18+
19+
return fig
20+
21+
22+
if __name__ == "__main__":
23+
fig = main()
24+
fig.show()
25.7 KB
Loading

docs/getting_started/getting_started.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,3 +287,20 @@ fig = ridgeplot(
287287
```{raw} html
288288
:file: ../_static/charts/lincoln_weather_red_blue.html
289289
```
290+
291+
## Theming with Plotly templates
292+
293+
Since `ridgeplot` is built on top of Plotly, you can also theme your ridgeline plots using [Plotly's figure templates](https://plotly.com/python/templates/). Simply pass the name of a registered template (or any other valid template representation) to the {py:paramref}`~ridgeplot.ridgeplot.template` parameter. For instance, taking the basic example from the top of this page and applying the `"plotly_dark"` template:
294+
295+
```python
296+
fig = ridgeplot(samples=my_samples, template="plotly_dark")
297+
fig.show()
298+
```
299+
300+
```{raw} html
301+
:file: ../_static/charts/basic_dark.html
302+
```
303+
304+
:::{note}
305+
Unless a custom {py:paramref}`~ridgeplot.ridgeplot.colorscale` is specified, the default colorscale will also be inferred from the specified template.
306+
:::

docs/reference/changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ Unreleased changes
99

1010
- Implement a new `template` parameter to allow users to specify a Plotly figure template ({gh-pr}`389`)
1111

12+
### Documentation
13+
14+
- Add a section on theming with Plotly templates to the getting started guide ({gh-pr}`389`)
15+
1216
### CI/CD
1317

1418
- Bump actions/download-artifact from 7 to 8 ({gh-pr}`368`)

tests/e2e/artifacts/basic_dark.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)