Skip to content

Commit 811aea6

Browse files
cyclical swatches function
1 parent 4d0b47c commit 811aea6

File tree

2 files changed

+53
-2
lines changed

2 files changed

+53
-2
lines changed

Diff for: packages/python/plotly/_plotly_utils/colors/_swatches.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def _swatches(module_names, module_contents, template=None):
2020
sequences = [
2121
(k, v)
2222
for k, v in module_contents.items()
23-
if not (k.startswith("_") or k == "swatches" or k.endswith("_r"))
23+
if not (k.startswith("_") or k.startswith("swatches") or k.endswith("_r"))
2424
]
2525

2626
return go.Figure(

Diff for: packages/python/plotly/_plotly_utils/colors/cyclical.py

+52-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,57 @@ def swatches(template=None):
1313

1414
swatches.__doc__ = _swatches.__doc__
1515

16+
17+
def swatches_cyclical(template=None):
18+
"""
19+
Parameters
20+
----------
21+
template : str or dict or plotly.graph_objects.layout.Template instance
22+
The figure template name or definition.
23+
24+
Returns
25+
-------
26+
fig : graph_objects.Figure containing the displayed image
27+
A `Figure` object. This figure demonstrates the color scales and
28+
sequences in this module, as polar bar charts.
29+
"""
30+
import plotly.graph_objects as go
31+
from plotly.subplots import make_subplots
32+
from plotly.express._core import apply_default_cascade
33+
34+
args = dict(template=template)
35+
apply_default_cascade(args)
36+
37+
rows = 2
38+
cols = 4
39+
scales = ["IceFire", "Twilight", "Edge", "Phase", "HSV", "mrybm", "mygbm"]
40+
fig = make_subplots(
41+
rows=rows,
42+
cols=cols,
43+
subplot_titles=scales,
44+
specs=[[{"type": "polar"}] * cols] * rows,
45+
)
46+
47+
for i, scale in enumerate(scales):
48+
fig.add_trace(
49+
go.Barpolar(
50+
r=[1] * int(360 / 5),
51+
theta=list(range(0, 360, 5)),
52+
marker_color=list(range(0, 360, 5)),
53+
marker_cmin=0,
54+
marker_cmax=360,
55+
marker_colorscale=scale,
56+
name=scale,
57+
),
58+
row=int(i / cols) + 1,
59+
col=i % cols + 1,
60+
)
61+
fig.update_traces(width=5.2, marker_line_width=0, base=0.5, showlegend=False)
62+
fig.update_polars(angularaxis_visible=False, radialaxis_visible=False)
63+
fig.update_layout(title="plotly.colors.cyclical", template=args["template"])
64+
return fig
65+
66+
1667
Twilight = [
1768
"#e2d9e2",
1869
"#9ebbc9",
@@ -131,6 +182,6 @@ def swatches(template=None):
131182
# Prefix variable names with _ so that they will not be added to the swatches
132183
_contents = dict(globals())
133184
for _k, _cols in _contents.items():
134-
if _k.startswith("_") or _k == "swatches" or _k.endswith("_r"):
185+
if _k.startswith("_") or _k.startswith("swatches") or _k.endswith("_r"):
135186
continue
136187
globals()[_k + "_r"] = _cols[::-1]

0 commit comments

Comments
 (0)