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] diff --git a/packages/python/plotly/_plotly_utils/colors/_swatches.py b/packages/python/plotly/_plotly_utils/colors/_swatches.py index ff07ff42907..9609249036b 100644 --- a/packages/python/plotly/_plotly_utils/colors/_swatches.py +++ b/packages/python/plotly/_plotly_utils/colors/_swatches.py @@ -1,10 +1,21 @@ -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) @@ -25,13 +36,13 @@ def _swatches(module_names, module_contents): for name, colors in reversed(sequences) ], layout=dict( - title=module_names, + title="plotly.colors." + module_names.split(".")[-1], 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__