|
4 | 4 | from typing import TYPE_CHECKING, Any |
5 | 5 |
|
6 | 6 | import plotly.express as px |
| 7 | +import plotly.io as pio |
7 | 8 | import pytest |
8 | 9 |
|
9 | 10 | from ridgeplot import ridgeplot |
@@ -171,6 +172,65 @@ def test_colorscale_invalid(invalid_colorscale: ColorScale | Collection[Color] | |
171 | 172 | ridgeplot(samples=[[[1, 2, 3], [4, 5, 6]]], colorscale=invalid_colorscale) |
172 | 173 |
|
173 | 174 |
|
| 175 | +# ============================================================== |
| 176 | +# --- param: template |
| 177 | +# ============================================================== |
| 178 | + |
| 179 | + |
| 180 | +def test_template_is_applied_to_the_figure() -> None: |
| 181 | + fig = ridgeplot(samples=[[[1, 2, 3], [4, 5, 6]]], template="plotly_dark") |
| 182 | + assert fig.layout.template == pio.templates["plotly_dark"] |
| 183 | + |
| 184 | + |
| 185 | +def test_template_equivalent_representations() -> None: |
| 186 | + samples = [[[1, 2, 3], [4, 5, 6]]] |
| 187 | + template = pio.templates["seaborn"] |
| 188 | + assert ( |
| 189 | + ridgeplot(samples=samples, template="seaborn") == |
| 190 | + ridgeplot(samples=samples, template=template) == |
| 191 | + ridgeplot(samples=samples, template=template.to_plotly_json()) |
| 192 | + ) # fmt: skip |
| 193 | + |
| 194 | + |
| 195 | +def test_template_default() -> None: |
| 196 | + # Not specifying a template should be equivalent to |
| 197 | + # specifying Plotly's current default template |
| 198 | + samples = [[[1, 2, 3], [4, 5, 6]]] |
| 199 | + assert ( |
| 200 | + ridgeplot(samples=samples) == |
| 201 | + ridgeplot(samples=samples, template=pio.templates.default or "plotly") |
| 202 | + ) # fmt: skip |
| 203 | + |
| 204 | + |
| 205 | +def test_template_sets_default_colorscale() -> None: |
| 206 | + # The default colorscale should be inferred from the |
| 207 | + # template specified via the `template` argument |
| 208 | + samples = [[[1, 2, 3], [4, 5, 6]]] |
| 209 | + template = pio.templates["ggplot2"] |
| 210 | + assert ( |
| 211 | + ridgeplot(samples=samples, template="ggplot2") == |
| 212 | + ridgeplot( |
| 213 | + samples=samples, |
| 214 | + template="ggplot2", |
| 215 | + colorscale=template.layout.colorscale.sequential, |
| 216 | + ) |
| 217 | + ) # fmt: skip |
| 218 | + |
| 219 | + |
| 220 | +def test_template_explicit_colorscale_takes_precedence() -> None: |
| 221 | + fig = ridgeplot( |
| 222 | + samples=[[[1, 2, 3], [4, 5, 6]]], |
| 223 | + template="ggplot2", |
| 224 | + colorscale=( |
| 225 | + (0.0, "rgb(10, 10, 10)"), |
| 226 | + (1.0, "rgb(20, 20, 20)"), |
| 227 | + ), |
| 228 | + colormode="trace-index", |
| 229 | + ) |
| 230 | + assert fig.data[1].fillcolor == "rgb(20, 20, 20)" |
| 231 | + assert fig.data[3].fillcolor == "rgb(10, 10, 10)" |
| 232 | + |
| 233 | + |
174 | 234 | # ============================================================== |
175 | 235 | # --- param: color_discrete_map |
176 | 236 | # ============================================================== |
|
0 commit comments