Skip to content

apply defaults cascade to swatches() #1886

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
Nov 11, 2019
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
9 changes: 9 additions & 0 deletions packages/python/plotly/_plotly_utils/colors/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
19 changes: 15 additions & 4 deletions packages/python/plotly/_plotly_utils/colors/_swatches.py
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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"],
),
)
4 changes: 2 additions & 2 deletions packages/python/plotly/_plotly_utils/colors/carto.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__
Expand Down
4 changes: 2 additions & 2 deletions packages/python/plotly/_plotly_utils/colors/cmocean.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__
Expand Down
4 changes: 2 additions & 2 deletions packages/python/plotly/_plotly_utils/colors/colorbrewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__
Expand Down
4 changes: 2 additions & 2 deletions packages/python/plotly/_plotly_utils/colors/cyclical.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__
Expand Down
4 changes: 2 additions & 2 deletions packages/python/plotly/_plotly_utils/colors/diverging.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__
4 changes: 2 additions & 2 deletions packages/python/plotly/_plotly_utils/colors/qualitative.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__
Expand Down
4 changes: 2 additions & 2 deletions packages/python/plotly/_plotly_utils/colors/sequential.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__
Expand Down