From 9838830e2fa05fb2cea0501435b18514ca7067f9 Mon Sep 17 00:00:00 2001 From: Nicolas Kruchten Date: Fri, 8 Nov 2019 20:50:36 -0500 Subject: [PATCH 1/4] apply defaults cascade to swatches() --- .../plotly/_plotly_utils/colors/_swatches.py | 19 ++++++++++++++++--- .../plotly/_plotly_utils/colors/carto.py | 4 ++-- .../plotly/_plotly_utils/colors/cmocean.py | 4 ++-- .../_plotly_utils/colors/colorbrewer.py | 4 ++-- .../plotly/_plotly_utils/colors/cyclical.py | 4 ++-- .../plotly/_plotly_utils/colors/diverging.py | 4 ++-- .../_plotly_utils/colors/qualitative.py | 4 ++-- .../plotly/_plotly_utils/colors/sequential.py | 4 ++-- 8 files changed, 30 insertions(+), 17 deletions(-) diff --git a/packages/python/plotly/_plotly_utils/colors/_swatches.py b/packages/python/plotly/_plotly_utils/colors/_swatches.py index ff07ff42907..632cf8fa9e2 100644 --- a/packages/python/plotly/_plotly_utils/colors/_swatches.py +++ b/packages/python/plotly/_plotly_utils/colors/_swatches.py @@ -1,10 +1,23 @@ -def _swatches(module_names, module_contents): +def _swatches(module_names, module_contents, template=None): """ - Returns: + 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 stacked bar charts. """ import plotly.graph_objs as go + from plotly.express._core import apply_default_cascade + + args = dict(template=template) + apply_default_cascade(args) sequences = [ (k, v) @@ -28,10 +41,10 @@ def _swatches(module_names, module_contents): title=module_names, barmode="stack", barnorm="fraction", - template="plotly", bargap=0.5, showlegend=False, xaxis=dict(range=[-0.02, 1.02], showticklabels=False, showgrid=False), height=max(600, 40 * len(sequences)), + template=args["template"], ), ) diff --git a/packages/python/plotly/_plotly_utils/colors/carto.py b/packages/python/plotly/_plotly_utils/colors/carto.py index c20d6b5d259..94b3785d5ed 100644 --- a/packages/python/plotly/_plotly_utils/colors/carto.py +++ b/packages/python/plotly/_plotly_utils/colors/carto.py @@ -9,8 +9,8 @@ from ._swatches import _swatches -def swatches(): - return _swatches(__name__, globals()) +def swatches(template=None): + return _swatches(__name__, globals(), template) swatches.__doc__ = _swatches.__doc__ diff --git a/packages/python/plotly/_plotly_utils/colors/cmocean.py b/packages/python/plotly/_plotly_utils/colors/cmocean.py index c7174fd60c0..029e4204428 100644 --- a/packages/python/plotly/_plotly_utils/colors/cmocean.py +++ b/packages/python/plotly/_plotly_utils/colors/cmocean.py @@ -9,8 +9,8 @@ from ._swatches import _swatches -def swatches(): - return _swatches(__name__, globals()) +def swatches(template=None): + return _swatches(__name__, globals(), template) swatches.__doc__ = _swatches.__doc__ diff --git a/packages/python/plotly/_plotly_utils/colors/colorbrewer.py b/packages/python/plotly/_plotly_utils/colors/colorbrewer.py index fa2e2b9a981..b21015ec615 100644 --- a/packages/python/plotly/_plotly_utils/colors/colorbrewer.py +++ b/packages/python/plotly/_plotly_utils/colors/colorbrewer.py @@ -9,8 +9,8 @@ from ._swatches import _swatches -def swatches(): - return _swatches(__name__, globals()) +def swatches(template=None): + return _swatches(__name__, globals(), template) swatches.__doc__ = _swatches.__doc__ diff --git a/packages/python/plotly/_plotly_utils/colors/cyclical.py b/packages/python/plotly/_plotly_utils/colors/cyclical.py index ec024865df6..235aee95fe0 100644 --- a/packages/python/plotly/_plotly_utils/colors/cyclical.py +++ b/packages/python/plotly/_plotly_utils/colors/cyclical.py @@ -7,8 +7,8 @@ from ._swatches import _swatches -def swatches(): - return _swatches(__name__, globals()) +def swatches(template=None): + return _swatches(__name__, globals(), template) swatches.__doc__ = _swatches.__doc__ diff --git a/packages/python/plotly/_plotly_utils/colors/diverging.py b/packages/python/plotly/_plotly_utils/colors/diverging.py index 0a1bf21db6e..eb6ca140da8 100644 --- a/packages/python/plotly/_plotly_utils/colors/diverging.py +++ b/packages/python/plotly/_plotly_utils/colors/diverging.py @@ -25,8 +25,8 @@ from ._swatches import _swatches -def swatches(): - return _swatches(__name__, globals()) +def swatches(template=None): + return _swatches(__name__, globals(), template) swatches.__doc__ = _swatches.__doc__ diff --git a/packages/python/plotly/_plotly_utils/colors/qualitative.py b/packages/python/plotly/_plotly_utils/colors/qualitative.py index 9984cc4b049..41fa555ed10 100644 --- a/packages/python/plotly/_plotly_utils/colors/qualitative.py +++ b/packages/python/plotly/_plotly_utils/colors/qualitative.py @@ -7,8 +7,8 @@ from ._swatches import _swatches -def swatches(): - return _swatches(__name__, globals()) +def swatches(template=None): + return _swatches(__name__, globals(), template) swatches.__doc__ = _swatches.__doc__ diff --git a/packages/python/plotly/_plotly_utils/colors/sequential.py b/packages/python/plotly/_plotly_utils/colors/sequential.py index 4b418dd8fa3..42fea40cd22 100644 --- a/packages/python/plotly/_plotly_utils/colors/sequential.py +++ b/packages/python/plotly/_plotly_utils/colors/sequential.py @@ -8,8 +8,8 @@ from ._swatches import _swatches -def swatches(): - return _swatches(__name__, globals()) +def swatches(template=None): + return _swatches(__name__, globals(), template) swatches.__doc__ = _swatches.__doc__ From 29cdd6b2250014d003fce06b580db774f0c20230 Mon Sep 17 00:00:00 2001 From: Nicolas Kruchten Date: Sat, 9 Nov 2019 16:13:51 -0500 Subject: [PATCH 2/4] fix swatch titles --- packages/python/plotly/_plotly_utils/colors/_swatches.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/python/plotly/_plotly_utils/colors/_swatches.py b/packages/python/plotly/_plotly_utils/colors/_swatches.py index 632cf8fa9e2..8d00a8e1577 100644 --- a/packages/python/plotly/_plotly_utils/colors/_swatches.py +++ b/packages/python/plotly/_plotly_utils/colors/_swatches.py @@ -38,7 +38,7 @@ def _swatches(module_names, module_contents, template=None): for name, colors in reversed(sequences) ], layout=dict( - title=module_names, + title="plotly.colors." + module_names.split(".")[-1], barmode="stack", barnorm="fraction", bargap=0.5, From 75ee6e1b4071df446741efb25c65c1dd82c1ab18 Mon Sep 17 00:00:00 2001 From: Nicolas Kruchten Date: Sat, 9 Nov 2019 16:26:29 -0500 Subject: [PATCH 3/4] easily access canonical list of named colorscales --- packages/python/plotly/_plotly_utils/colors/__init__.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/python/plotly/_plotly_utils/colors/__init__.py b/packages/python/plotly/_plotly_utils/colors/__init__.py index 2f344de3eaf..b7669ce4d21 100644 --- a/packages/python/plotly/_plotly_utils/colors/__init__.py +++ b/packages/python/plotly/_plotly_utils/colors/__init__.py @@ -797,3 +797,12 @@ def convert_colorscale_to_rgb(colorscale): for color in colorscale: color[1] = label_rgb(color[1]) return colorscale + + +def named_colorscales(): + """ + Returns lowercased names of built-in continuous colorscales. + """ + from _plotly_utils.basevalidators import ColorscaleValidator + + return [c for c in ColorscaleValidator("", "").named_colorscales] From 81a56c5e53b8f136d6aed592830575f8ae597a05 Mon Sep 17 00:00:00 2001 From: Nicolas Kruchten Date: Mon, 11 Nov 2019 09:31:08 -0500 Subject: [PATCH 4/4] Apply suggestions from code review Co-Authored-By: Joel Ostblom --- packages/python/plotly/_plotly_utils/colors/_swatches.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/python/plotly/_plotly_utils/colors/_swatches.py b/packages/python/plotly/_plotly_utils/colors/_swatches.py index 8d00a8e1577..9609249036b 100644 --- a/packages/python/plotly/_plotly_utils/colors/_swatches.py +++ b/packages/python/plotly/_plotly_utils/colors/_swatches.py @@ -2,13 +2,11 @@ def _swatches(module_names, module_contents, 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 stacked bar charts.