From e9ff292d4f9566f7e1235ba528ce7aad7ad76235 Mon Sep 17 00:00:00 2001 From: Nicolas Kruchten Date: Wed, 25 Dec 2019 12:21:32 -0500 Subject: [PATCH 1/4] first and last color of cyclicals should match --- packages/python/plotly/_plotly_utils/colors/cyclical.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/python/plotly/_plotly_utils/colors/cyclical.py b/packages/python/plotly/_plotly_utils/colors/cyclical.py index 254fa830810..19daf118b8d 100644 --- a/packages/python/plotly/_plotly_utils/colors/cyclical.py +++ b/packages/python/plotly/_plotly_utils/colors/cyclical.py @@ -42,7 +42,7 @@ def swatches(template=None): "#ac2301", "#820000", "#4c0000", - "#040100", + "#000000", ] Edge = [ "#313131", @@ -87,7 +87,7 @@ def swatches(template=None): "#0010ff", "#9700ff", "#ff00bf", - "#ff0018", + "#ff0000", ] mrybm = [ "#f884f7", @@ -106,6 +106,7 @@ def swatches(template=None): "#6b4ef9", "#956bfa", "#cd7dfe", + "#f884f7", ] mygbm = [ "#ef55f1", @@ -124,6 +125,7 @@ def swatches(template=None): "#6324f5", "#9139fa", "#c543fa", + "#ef55f1", ] # Prefix variable names with _ so that they will not be added to the swatches From 827225844a45435c5920c8714dca92ee4781bbb9 Mon Sep 17 00:00:00 2001 From: Nicolas Kruchten Date: Wed, 25 Dec 2019 21:25:47 -0500 Subject: [PATCH 2/4] cyclical swatches function --- .../plotly/_plotly_utils/colors/_swatches.py | 2 +- .../plotly/_plotly_utils/colors/cyclical.py | 53 ++++++++++++++++++- 2 files changed, 53 insertions(+), 2 deletions(-) diff --git a/packages/python/plotly/_plotly_utils/colors/_swatches.py b/packages/python/plotly/_plotly_utils/colors/_swatches.py index a8c776a3467..61e72db1f25 100644 --- a/packages/python/plotly/_plotly_utils/colors/_swatches.py +++ b/packages/python/plotly/_plotly_utils/colors/_swatches.py @@ -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( diff --git a/packages/python/plotly/_plotly_utils/colors/cyclical.py b/packages/python/plotly/_plotly_utils/colors/cyclical.py index 19daf118b8d..c6a8eaca718 100644 --- a/packages/python/plotly/_plotly_utils/colors/cyclical.py +++ b/packages/python/plotly/_plotly_utils/colors/cyclical.py @@ -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 = ["IceFire", "Twilight", "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", @@ -131,6 +182,6 @@ def swatches(template=None): # 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] From d886b2f6bb329dba39ee190ea3cb7260304bcf5e Mon Sep 17 00:00:00 2001 From: Nicolas Kruchten Date: Wed, 15 Jan 2020 14:39:16 -0500 Subject: [PATCH 3/4] using swatches_cyclical in docs --- doc/python/builtin-colorscales.md | 18 ++++++++++++++---- .../plotly/_plotly_utils/colors/_swatches.py | 1 + .../plotly/_plotly_utils/colors/cyclical.py | 2 +- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/doc/python/builtin-colorscales.md b/doc/python/builtin-colorscales.md index 03d51042e3c..50a424fe5d4 100644 --- a/doc/python/builtin-colorscales.md +++ b/doc/python/builtin-colorscales.md @@ -5,7 +5,7 @@ jupyter: text_representation: extension: .md format_name: markdown - format_version: "1.2" + format_version: '1.2' jupytext_version: 1.3.1 kernelspec: display_name: Python 3 @@ -22,8 +22,7 @@ jupyter: pygments_lexer: ipython3 version: 3.6.8 plotly: - description: - A reference for the built-in named continuous (sequential, diverging + description: A reference for the built-in named continuous (sequential, diverging and cylclical) color scales in Plotly. display_as: file_settings has_thumbnail: true @@ -103,7 +102,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() ``` @@ -119,6 +118,17 @@ 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() ``` + +```python + +``` + +```python +xx +``` diff --git a/packages/python/plotly/_plotly_utils/colors/_swatches.py b/packages/python/plotly/_plotly_utils/colors/_swatches.py index 61e72db1f25..7c9b230c12c 100644 --- a/packages/python/plotly/_plotly_utils/colors/_swatches.py +++ b/packages/python/plotly/_plotly_utils/colors/_swatches.py @@ -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), ), ) diff --git a/packages/python/plotly/_plotly_utils/colors/cyclical.py b/packages/python/plotly/_plotly_utils/colors/cyclical.py index c6a8eaca718..1c7315268fa 100644 --- a/packages/python/plotly/_plotly_utils/colors/cyclical.py +++ b/packages/python/plotly/_plotly_utils/colors/cyclical.py @@ -36,7 +36,7 @@ def swatches_cyclical(template=None): rows = 2 cols = 4 - scales = ["IceFire", "Twilight", "Edge", "Phase", "HSV", "mrybm", "mygbm"] + scales = ["Twilight", "IceFire", "Edge", "Phase", "HSV", "mrybm", "mygbm"] fig = make_subplots( rows=rows, cols=cols, From 515881762e35f4186fd8acbfe48d9cea985d89f1 Mon Sep 17 00:00:00 2001 From: Nicolas Kruchten Date: Wed, 15 Jan 2020 14:49:03 -0500 Subject: [PATCH 4/4] typo --- doc/python/builtin-colorscales.md | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/doc/python/builtin-colorscales.md b/doc/python/builtin-colorscales.md index 50a424fe5d4..77413839e54 100644 --- a/doc/python/builtin-colorscales.md +++ b/doc/python/builtin-colorscales.md @@ -5,7 +5,7 @@ jupyter: text_representation: extension: .md format_name: markdown - format_version: '1.2' + format_version: "1.2" jupytext_version: 1.3.1 kernelspec: display_name: Python 3 @@ -22,7 +22,8 @@ jupyter: pygments_lexer: ipython3 version: 3.6.8 plotly: - description: A reference for the built-in named continuous (sequential, diverging + description: + A reference for the built-in named continuous (sequential, diverging and cylclical) color scales in Plotly. display_as: file_settings has_thumbnail: true @@ -124,11 +125,3 @@ fig.show() fig = px.colors.cyclical.swatches() fig.show() ``` - -```python - -``` - -```python -xx -```