Skip to content

Commit 5ac8f55

Browse files
Merge pull request #2016 from plotly/cyclical_fix
first and last color of cyclicals should match
2 parents 912954d + 5158817 commit 5ac8f55

File tree

3 files changed

+62
-5
lines changed

3 files changed

+62
-5
lines changed

Diff for: doc/python/builtin-colorscales.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ Here are all the built-in scales in the `plotly.colors.diverging` module:
103103
```python
104104
import plotly.express as px
105105

106-
fig = px.colors.diverging.swatches()
106+
fig = px.colors.diverging.swatches().update_layout(margin_b=10)
107107
fig.show()
108108
```
109109

@@ -119,6 +119,9 @@ Here are all the built-in scales in the `plotly.colors.cyclical` module:
119119
```python
120120
import plotly.express as px
121121

122+
fig = px.colors.cyclical.swatches_cyclical()
123+
fig.show()
124+
122125
fig = px.colors.cyclical.swatches()
123126
fig.show()
124127
```

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

+2-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(
@@ -44,5 +44,6 @@ def _swatches(module_names, module_contents, template=None):
4444
xaxis=dict(range=[-0.02, 1.02], showticklabels=False, showgrid=False),
4545
height=max(600, 40 * len(sequences)),
4646
template=args["template"],
47+
margin=dict(b=10),
4748
),
4849
)

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

+56-3
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 = ["Twilight", "IceFire", "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",
@@ -42,7 +93,7 @@ def swatches(template=None):
4293
"#ac2301",
4394
"#820000",
4495
"#4c0000",
45-
"#040100",
96+
"#000000",
4697
]
4798
Edge = [
4899
"#313131",
@@ -87,7 +138,7 @@ def swatches(template=None):
87138
"#0010ff",
88139
"#9700ff",
89140
"#ff00bf",
90-
"#ff0018",
141+
"#ff0000",
91142
]
92143
mrybm = [
93144
"#f884f7",
@@ -106,6 +157,7 @@ def swatches(template=None):
106157
"#6b4ef9",
107158
"#956bfa",
108159
"#cd7dfe",
160+
"#f884f7",
109161
]
110162
mygbm = [
111163
"#ef55f1",
@@ -124,11 +176,12 @@ def swatches(template=None):
124176
"#6324f5",
125177
"#9139fa",
126178
"#c543fa",
179+
"#ef55f1",
127180
]
128181

129182
# Prefix variable names with _ so that they will not be added to the swatches
130183
_contents = dict(globals())
131184
for _k, _cols in _contents.items():
132-
if _k.startswith("_") or _k == "swatches" or _k.endswith("_r"):
185+
if _k.startswith("_") or _k.startswith("swatches") or _k.endswith("_r"):
133186
continue
134187
globals()[_k + "_r"] = _cols[::-1]

0 commit comments

Comments
 (0)