Skip to content

first and last color of cyclicals should match #2016

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion doc/python/builtin-colorscales.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ Here are all the built-in scales in the `plotly.colors.diverging` module:
```python
import plotly.express as px

fig = px.colors.diverging.swatches()
fig = px.colors.diverging.swatches().update_layout(margin_b=10)
fig.show()
```

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

fig = px.colors.cyclical.swatches_cyclical()
fig.show()

fig = px.colors.cyclical.swatches()
fig.show()
```
3 changes: 2 additions & 1 deletion packages/python/plotly/_plotly_utils/colors/_swatches.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def _swatches(module_names, module_contents, template=None):
sequences = [
(k, v)
for k, v in module_contents.items()
if not (k.startswith("_") or k == "swatches" or k.endswith("_r"))
if not (k.startswith("_") or k.startswith("swatches") or k.endswith("_r"))
]

return go.Figure(
Expand All @@ -44,5 +44,6 @@ def _swatches(module_names, module_contents, template=None):
xaxis=dict(range=[-0.02, 1.02], showticklabels=False, showgrid=False),
height=max(600, 40 * len(sequences)),
template=args["template"],
margin=dict(b=10),
),
)
59 changes: 56 additions & 3 deletions packages/python/plotly/_plotly_utils/colors/cyclical.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,57 @@ def swatches(template=None):

swatches.__doc__ = _swatches.__doc__


def swatches_cyclical(template=None):
"""
Parameters
----------
template : str or dict or plotly.graph_objects.layout.Template instance
The figure template name or definition.

Returns
-------
fig : graph_objects.Figure containing the displayed image
A `Figure` object. This figure demonstrates the color scales and
sequences in this module, as polar bar charts.
"""
import plotly.graph_objects as go
from plotly.subplots import make_subplots
from plotly.express._core import apply_default_cascade

args = dict(template=template)
apply_default_cascade(args)

rows = 2
cols = 4
scales = ["Twilight", "IceFire", "Edge", "Phase", "HSV", "mrybm", "mygbm"]
fig = make_subplots(
rows=rows,
cols=cols,
subplot_titles=scales,
specs=[[{"type": "polar"}] * cols] * rows,
)

for i, scale in enumerate(scales):
fig.add_trace(
go.Barpolar(
r=[1] * int(360 / 5),
theta=list(range(0, 360, 5)),
marker_color=list(range(0, 360, 5)),
marker_cmin=0,
marker_cmax=360,
marker_colorscale=scale,
name=scale,
),
row=int(i / cols) + 1,
col=i % cols + 1,
)
fig.update_traces(width=5.2, marker_line_width=0, base=0.5, showlegend=False)
fig.update_polars(angularaxis_visible=False, radialaxis_visible=False)
fig.update_layout(title="plotly.colors.cyclical", template=args["template"])
return fig


Twilight = [
"#e2d9e2",
"#9ebbc9",
Expand Down Expand Up @@ -42,7 +93,7 @@ def swatches(template=None):
"#ac2301",
"#820000",
"#4c0000",
"#040100",
"#000000",
]
Edge = [
"#313131",
Expand Down Expand Up @@ -87,7 +138,7 @@ def swatches(template=None):
"#0010ff",
"#9700ff",
"#ff00bf",
"#ff0018",
"#ff0000",
]
mrybm = [
"#f884f7",
Expand All @@ -106,6 +157,7 @@ def swatches(template=None):
"#6b4ef9",
"#956bfa",
"#cd7dfe",
"#f884f7",
]
mygbm = [
"#ef55f1",
Expand All @@ -124,11 +176,12 @@ def swatches(template=None):
"#6324f5",
"#9139fa",
"#c543fa",
"#ef55f1",
]

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