Skip to content

Commit 1ca5ba8

Browse files
Merge pull request #1886 from plotly/swatch_templates
apply defaults cascade to swatches()
2 parents 60b0f69 + 81a56c5 commit 1ca5ba8

File tree

9 files changed

+38
-18
lines changed

9 files changed

+38
-18
lines changed

packages/python/plotly/_plotly_utils/colors/__init__.py

+9
Original file line numberDiff line numberDiff line change
@@ -797,3 +797,12 @@ def convert_colorscale_to_rgb(colorscale):
797797
for color in colorscale:
798798
color[1] = label_rgb(color[1])
799799
return colorscale
800+
801+
802+
def named_colorscales():
803+
"""
804+
Returns lowercased names of built-in continuous colorscales.
805+
"""
806+
from _plotly_utils.basevalidators import ColorscaleValidator
807+
808+
return [c for c in ColorscaleValidator("", "").named_colorscales]

packages/python/plotly/_plotly_utils/colors/_swatches.py

+15-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
1-
def _swatches(module_names, module_contents):
1+
def _swatches(module_names, module_contents, template=None):
22
"""
3-
Returns:
3+
Parameters
4+
----------
5+
template : str or dict or plotly.graph_objects.layout.Template instance
6+
The figure template name or definition.
7+
8+
Returns
9+
-------
10+
fig : graph_objects.Figure containing the displayed image
411
A `Figure` object. This figure demonstrates the color scales and
512
sequences in this module, as stacked bar charts.
613
"""
714
import plotly.graph_objs as go
15+
from plotly.express._core import apply_default_cascade
16+
17+
args = dict(template=template)
18+
apply_default_cascade(args)
819

920
sequences = [
1021
(k, v)
@@ -25,13 +36,13 @@ def _swatches(module_names, module_contents):
2536
for name, colors in reversed(sequences)
2637
],
2738
layout=dict(
28-
title=module_names,
39+
title="plotly.colors." + module_names.split(".")[-1],
2940
barmode="stack",
3041
barnorm="fraction",
31-
template="plotly",
3242
bargap=0.5,
3343
showlegend=False,
3444
xaxis=dict(range=[-0.02, 1.02], showticklabels=False, showgrid=False),
3545
height=max(600, 40 * len(sequences)),
46+
template=args["template"],
3647
),
3748
)

packages/python/plotly/_plotly_utils/colors/carto.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
from ._swatches import _swatches
1010

1111

12-
def swatches():
13-
return _swatches(__name__, globals())
12+
def swatches(template=None):
13+
return _swatches(__name__, globals(), template)
1414

1515

1616
swatches.__doc__ = _swatches.__doc__

packages/python/plotly/_plotly_utils/colors/cmocean.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
from ._swatches import _swatches
1010

1111

12-
def swatches():
13-
return _swatches(__name__, globals())
12+
def swatches(template=None):
13+
return _swatches(__name__, globals(), template)
1414

1515

1616
swatches.__doc__ = _swatches.__doc__

packages/python/plotly/_plotly_utils/colors/colorbrewer.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
from ._swatches import _swatches
1010

1111

12-
def swatches():
13-
return _swatches(__name__, globals())
12+
def swatches(template=None):
13+
return _swatches(__name__, globals(), template)
1414

1515

1616
swatches.__doc__ = _swatches.__doc__

packages/python/plotly/_plotly_utils/colors/cyclical.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
from ._swatches import _swatches
88

99

10-
def swatches():
11-
return _swatches(__name__, globals())
10+
def swatches(template=None):
11+
return _swatches(__name__, globals(), template)
1212

1313

1414
swatches.__doc__ = _swatches.__doc__

packages/python/plotly/_plotly_utils/colors/diverging.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
from ._swatches import _swatches
2626

2727

28-
def swatches():
29-
return _swatches(__name__, globals())
28+
def swatches(template=None):
29+
return _swatches(__name__, globals(), template)
3030

3131

3232
swatches.__doc__ = _swatches.__doc__

packages/python/plotly/_plotly_utils/colors/qualitative.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
from ._swatches import _swatches
88

99

10-
def swatches():
11-
return _swatches(__name__, globals())
10+
def swatches(template=None):
11+
return _swatches(__name__, globals(), template)
1212

1313

1414
swatches.__doc__ = _swatches.__doc__

packages/python/plotly/_plotly_utils/colors/sequential.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
from ._swatches import _swatches
99

1010

11-
def swatches():
12-
return _swatches(__name__, globals())
11+
def swatches(template=None):
12+
return _swatches(__name__, globals(), template)
1313

1414

1515
swatches.__doc__ = _swatches.__doc__

0 commit comments

Comments
 (0)