Skip to content
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

Reversed colorscale #1933

Merged
merged 17 commits into from
Dec 10, 2019
14 changes: 10 additions & 4 deletions packages/python/plotly/_plotly_utils/basevalidators.py
Original file line number Diff line number Diff line change
Expand Up @@ -1532,6 +1532,8 @@ def named_colorscales(self):
and len(c) == 2
and isinstance(c[0], str)
and isinstance(c[1], list)
and not c[0].endswith("_r")
and not c[0].startswith("_")
}

return self._named_colorscales
Expand All @@ -1558,7 +1560,8 @@ def description(self):
and the second item is a valid color string.
(e.g. [[0, 'green'], [0.5, 'red'], [1.0, 'rgb(0, 0, 255)']])
- One of the following named colorscales:
{colorscales_str}
{colorscales_str}.
Appending '_r' to a named colorscale reverses it.
""".format(
plotly_name=self.plotly_name, colorscales_str=colorscales_str
)
Expand All @@ -1575,13 +1578,16 @@ def validate_coerce(self, v):
if v_lower in self.named_colorscales:
# Convert to color list
v = self.named_colorscales[v_lower]

v_valid = True
elif v_lower.endswith("_r") and v_lower[:-2] in self.named_colorscales:
v = self.named_colorscales[v_lower[:-2]][::-1]
v_valid = True
#
if v_valid:
# Convert to list of lists colorscale
d = len(v) - 1
v = [[(1.0 * i) / (1.0 * d), x] for i, x in enumerate(v)]

v_valid = True

elif is_array(v) and len(v) > 0:
# If firset element is a string, treat as colorsequence
if isinstance(v[0], string_types):
Expand Down
2 changes: 1 addition & 1 deletion packages/python/plotly/_plotly_utils/colors/_swatches.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
if not (k.startswith("_") or k == "swatches" or k.endswith("_r"))
]

return go.Figure(
Expand Down
7 changes: 7 additions & 0 deletions packages/python/plotly/_plotly_utils/colors/carto.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,3 +382,10 @@ def swatches(template=None):
"rgb(237, 100, 90)",
"rgb(165, 170, 153)",
]

# 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"):
continue
globals()[_k + "_r"] = _cols[::-1]
7 changes: 7 additions & 0 deletions packages/python/plotly/_plotly_utils/colors/cmocean.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,3 +267,10 @@ def swatches(template=None):
"rgb(111, 23, 91)",
"rgb(51, 13, 53)",
]

# 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"):
continue
globals()[_k + "_r"] = _cols[::-1]
7 changes: 7 additions & 0 deletions packages/python/plotly/_plotly_utils/colors/colorbrewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,3 +456,10 @@ def swatches(template=None):
"rgb(189,0,38)",
"rgb(128,0,38)",
]

# 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"):
continue
globals()[_k + "_r"] = _cols[::-1]
7 changes: 7 additions & 0 deletions packages/python/plotly/_plotly_utils/colors/cyclical.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,10 @@ def swatches(template=None):
"#9139fa",
"#c543fa",
]

# 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"):
continue
globals()[_k + "_r"] = _cols[::-1]
7 changes: 7 additions & 0 deletions packages/python/plotly/_plotly_utils/colors/diverging.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,10 @@ def swatches(template=None):


swatches.__doc__ = _swatches.__doc__

# 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"):
continue
globals()[_k + "_r"] = _cols[::-1]
7 changes: 7 additions & 0 deletions packages/python/plotly/_plotly_utils/colors/plotlyjs.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,10 @@
scale_name=scale_name, scale_sequence=scale_sequence
)
)

# 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"):
continue
globals()[_k + "_r"] = _cols[::-1]
7 changes: 7 additions & 0 deletions packages/python/plotly/_plotly_utils/colors/qualitative.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,10 @@ def swatches(template=None):

from .colorbrewer import Set1, Pastel1, Dark2, Set2, Pastel2, Set3 # noqa: F401
from .carto import Antique, Bold, Pastel, Prism, Safe, Vivid # noqa: F401

# 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"):
continue
globals()[_k + "_r"] = _cols[::-1]
7 changes: 7 additions & 0 deletions packages/python/plotly/_plotly_utils/colors/sequential.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,10 @@ def swatches(template=None):
Agsunset,
Brwnyl,
)

# 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"):
continue
globals()[_k + "_r"] = _cols[::-1]
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def validator():
and len(c) == 2
and isinstance(c[0], str)
and isinstance(c[1], list)
and not c[0].startswith("_")
}


Expand Down
45 changes: 30 additions & 15 deletions packages/python/plotly/plotly/graph_objs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2870,7 +2870,8 @@ def colorscale(self):
'rdpu', 'rdylbu', 'rdylgn', 'redor', 'reds', 'solar', 'spectral',
'speed', 'sunset', 'sunsetdark', 'teal', 'tealgrn', 'tealrose',
'tempo', 'temps', 'thermal', 'tropic', 'turbid', 'twilight',
'viridis', 'ylgn', 'ylgnbu', 'ylorbr', 'ylorrd']
'viridis', 'ylgn', 'ylgnbu', 'ylorbr', 'ylorrd'].
Appending '_r' to a named colorscale reverses it.

Returns
-------
Expand Down Expand Up @@ -10330,7 +10331,8 @@ def colorscale(self):
'rdpu', 'rdylbu', 'rdylgn', 'redor', 'reds', 'solar', 'spectral',
'speed', 'sunset', 'sunsetdark', 'teal', 'tealgrn', 'tealrose',
'tempo', 'temps', 'thermal', 'tropic', 'turbid', 'twilight',
'viridis', 'ylgn', 'ylgnbu', 'ylorbr', 'ylorrd']
'viridis', 'ylgn', 'ylgnbu', 'ylorbr', 'ylorrd'].
Appending '_r' to a named colorscale reverses it.

Returns
-------
Expand Down Expand Up @@ -14320,7 +14322,8 @@ def colorscale(self):
'rdpu', 'rdylbu', 'rdylgn', 'redor', 'reds', 'solar', 'spectral',
'speed', 'sunset', 'sunsetdark', 'teal', 'tealgrn', 'tealrose',
'tempo', 'temps', 'thermal', 'tropic', 'turbid', 'twilight',
'viridis', 'ylgn', 'ylgnbu', 'ylorbr', 'ylorrd']
'viridis', 'ylgn', 'ylgnbu', 'ylorbr', 'ylorrd'].
Appending '_r' to a named colorscale reverses it.

Returns
-------
Expand Down Expand Up @@ -46588,7 +46591,8 @@ def colorscale(self):
'rdpu', 'rdylbu', 'rdylgn', 'redor', 'reds', 'solar', 'spectral',
'speed', 'sunset', 'sunsetdark', 'teal', 'tealgrn', 'tealrose',
'tempo', 'temps', 'thermal', 'tropic', 'turbid', 'twilight',
'viridis', 'ylgn', 'ylgnbu', 'ylorbr', 'ylorrd']
'viridis', 'ylgn', 'ylgnbu', 'ylorbr', 'ylorrd'].
Appending '_r' to a named colorscale reverses it.

Returns
-------
Expand Down Expand Up @@ -49198,7 +49202,8 @@ def colorscale(self):
'rdpu', 'rdylbu', 'rdylgn', 'redor', 'reds', 'solar', 'spectral',
'speed', 'sunset', 'sunsetdark', 'teal', 'tealgrn', 'tealrose',
'tempo', 'temps', 'thermal', 'tropic', 'turbid', 'twilight',
'viridis', 'ylgn', 'ylgnbu', 'ylorbr', 'ylorrd']
'viridis', 'ylgn', 'ylgnbu', 'ylorbr', 'ylorrd'].
Appending '_r' to a named colorscale reverses it.

Returns
-------
Expand Down Expand Up @@ -53649,7 +53654,8 @@ def colorscale(self):
'rdpu', 'rdylbu', 'rdylgn', 'redor', 'reds', 'solar', 'spectral',
'speed', 'sunset', 'sunsetdark', 'teal', 'tealgrn', 'tealrose',
'tempo', 'temps', 'thermal', 'tropic', 'turbid', 'twilight',
'viridis', 'ylgn', 'ylgnbu', 'ylorbr', 'ylorrd']
'viridis', 'ylgn', 'ylgnbu', 'ylorbr', 'ylorrd'].
Appending '_r' to a named colorscale reverses it.

Returns
-------
Expand Down Expand Up @@ -56285,7 +56291,8 @@ def colorscale(self):
'rdpu', 'rdylbu', 'rdylgn', 'redor', 'reds', 'solar', 'spectral',
'speed', 'sunset', 'sunsetdark', 'teal', 'tealgrn', 'tealrose',
'tempo', 'temps', 'thermal', 'tropic', 'turbid', 'twilight',
'viridis', 'ylgn', 'ylgnbu', 'ylorbr', 'ylorrd']
'viridis', 'ylgn', 'ylgnbu', 'ylorbr', 'ylorrd'].
Appending '_r' to a named colorscale reverses it.

Returns
-------
Expand Down Expand Up @@ -61005,7 +61012,8 @@ def colorscale(self):
'rdpu', 'rdylbu', 'rdylgn', 'redor', 'reds', 'solar', 'spectral',
'speed', 'sunset', 'sunsetdark', 'teal', 'tealgrn', 'tealrose',
'tempo', 'temps', 'thermal', 'tropic', 'turbid', 'twilight',
'viridis', 'ylgn', 'ylgnbu', 'ylorbr', 'ylorrd']
'viridis', 'ylgn', 'ylgnbu', 'ylorbr', 'ylorrd'].
Appending '_r' to a named colorscale reverses it.

Returns
-------
Expand Down Expand Up @@ -62845,7 +62853,8 @@ def colorscale(self):
'rdpu', 'rdylbu', 'rdylgn', 'redor', 'reds', 'solar', 'spectral',
'speed', 'sunset', 'sunsetdark', 'teal', 'tealgrn', 'tealrose',
'tempo', 'temps', 'thermal', 'tropic', 'turbid', 'twilight',
'viridis', 'ylgn', 'ylgnbu', 'ylorbr', 'ylorrd']
'viridis', 'ylgn', 'ylgnbu', 'ylorbr', 'ylorrd'].
Appending '_r' to a named colorscale reverses it.

Returns
-------
Expand Down Expand Up @@ -69237,7 +69246,8 @@ def colorscale(self):
'rdpu', 'rdylbu', 'rdylgn', 'redor', 'reds', 'solar', 'spectral',
'speed', 'sunset', 'sunsetdark', 'teal', 'tealgrn', 'tealrose',
'tempo', 'temps', 'thermal', 'tropic', 'turbid', 'twilight',
'viridis', 'ylgn', 'ylgnbu', 'ylorbr', 'ylorrd']
'viridis', 'ylgn', 'ylgnbu', 'ylorbr', 'ylorrd'].
Appending '_r' to a named colorscale reverses it.

Returns
-------
Expand Down Expand Up @@ -71326,7 +71336,8 @@ def colorscale(self):
'rdpu', 'rdylbu', 'rdylgn', 'redor', 'reds', 'solar', 'spectral',
'speed', 'sunset', 'sunsetdark', 'teal', 'tealgrn', 'tealrose',
'tempo', 'temps', 'thermal', 'tropic', 'turbid', 'twilight',
'viridis', 'ylgn', 'ylgnbu', 'ylorbr', 'ylorrd']
'viridis', 'ylgn', 'ylgnbu', 'ylorbr', 'ylorrd'].
Appending '_r' to a named colorscale reverses it.

Returns
-------
Expand Down Expand Up @@ -73293,7 +73304,8 @@ def colorscale(self):
'rdpu', 'rdylbu', 'rdylgn', 'redor', 'reds', 'solar', 'spectral',
'speed', 'sunset', 'sunsetdark', 'teal', 'tealgrn', 'tealrose',
'tempo', 'temps', 'thermal', 'tropic', 'turbid', 'twilight',
'viridis', 'ylgn', 'ylgnbu', 'ylorbr', 'ylorrd']
'viridis', 'ylgn', 'ylgnbu', 'ylorbr', 'ylorrd'].
Appending '_r' to a named colorscale reverses it.

Returns
-------
Expand Down Expand Up @@ -75945,7 +75957,8 @@ def colorscale(self):
'rdpu', 'rdylbu', 'rdylgn', 'redor', 'reds', 'solar', 'spectral',
'speed', 'sunset', 'sunsetdark', 'teal', 'tealgrn', 'tealrose',
'tempo', 'temps', 'thermal', 'tropic', 'turbid', 'twilight',
'viridis', 'ylgn', 'ylgnbu', 'ylorbr', 'ylorrd']
'viridis', 'ylgn', 'ylgnbu', 'ylorbr', 'ylorrd'].
Appending '_r' to a named colorscale reverses it.

Returns
-------
Expand Down Expand Up @@ -78055,7 +78068,8 @@ def colorscale(self):
'rdpu', 'rdylbu', 'rdylgn', 'redor', 'reds', 'solar', 'spectral',
'speed', 'sunset', 'sunsetdark', 'teal', 'tealgrn', 'tealrose',
'tempo', 'temps', 'thermal', 'tropic', 'turbid', 'twilight',
'viridis', 'ylgn', 'ylgnbu', 'ylorbr', 'ylorrd']
'viridis', 'ylgn', 'ylgnbu', 'ylorbr', 'ylorrd'].
Appending '_r' to a named colorscale reverses it.

Returns
-------
Expand Down Expand Up @@ -79952,7 +79966,8 @@ def colorscale(self):
'rdpu', 'rdylbu', 'rdylgn', 'redor', 'reds', 'solar', 'spectral',
'speed', 'sunset', 'sunsetdark', 'teal', 'tealgrn', 'tealrose',
'tempo', 'temps', 'thermal', 'tropic', 'turbid', 'twilight',
'viridis', 'ylgn', 'ylgnbu', 'ylorbr', 'ylorrd']
'viridis', 'ylgn', 'ylgnbu', 'ylorbr', 'ylorrd'].
Appending '_r' to a named colorscale reverses it.

Returns
-------
Expand Down
3 changes: 2 additions & 1 deletion packages/python/plotly/plotly/graph_objs/bar/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1569,7 +1569,8 @@ def colorscale(self):
'rdpu', 'rdylbu', 'rdylgn', 'redor', 'reds', 'solar', 'spectral',
'speed', 'sunset', 'sunsetdark', 'teal', 'tealgrn', 'tealrose',
'tempo', 'temps', 'thermal', 'tropic', 'turbid', 'twilight',
'viridis', 'ylgn', 'ylgnbu', 'ylorbr', 'ylorrd']
'viridis', 'ylgn', 'ylgnbu', 'ylorbr', 'ylorrd'].
Appending '_r' to a named colorscale reverses it.

Returns
-------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,8 @@ def colorscale(self):
'rdpu', 'rdylbu', 'rdylgn', 'redor', 'reds', 'solar', 'spectral',
'speed', 'sunset', 'sunsetdark', 'teal', 'tealgrn', 'tealrose',
'tempo', 'temps', 'thermal', 'tropic', 'turbid', 'twilight',
'viridis', 'ylgn', 'ylgnbu', 'ylorbr', 'ylorrd']
'viridis', 'ylgn', 'ylgnbu', 'ylorbr', 'ylorrd'].
Appending '_r' to a named colorscale reverses it.

Returns
-------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -929,7 +929,8 @@ def colorscale(self):
'rdpu', 'rdylbu', 'rdylgn', 'redor', 'reds', 'solar', 'spectral',
'speed', 'sunset', 'sunsetdark', 'teal', 'tealgrn', 'tealrose',
'tempo', 'temps', 'thermal', 'tropic', 'turbid', 'twilight',
'viridis', 'ylgn', 'ylgnbu', 'ylorbr', 'ylorrd']
'viridis', 'ylgn', 'ylgnbu', 'ylorbr', 'ylorrd'].
Appending '_r' to a named colorscale reverses it.

Returns
-------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,8 @@ def colorscale(self):
'rdpu', 'rdylbu', 'rdylgn', 'redor', 'reds', 'solar', 'spectral',
'speed', 'sunset', 'sunsetdark', 'teal', 'tealgrn', 'tealrose',
'tempo', 'temps', 'thermal', 'tropic', 'turbid', 'twilight',
'viridis', 'ylgn', 'ylgnbu', 'ylorbr', 'ylorrd']
'viridis', 'ylgn', 'ylgnbu', 'ylorbr', 'ylorrd'].
Appending '_r' to a named colorscale reverses it.

Returns
-------
Expand Down
3 changes: 2 additions & 1 deletion packages/python/plotly/plotly/graph_objs/funnel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1275,7 +1275,8 @@ def colorscale(self):
'rdpu', 'rdylbu', 'rdylgn', 'redor', 'reds', 'solar', 'spectral',
'speed', 'sunset', 'sunsetdark', 'teal', 'tealgrn', 'tealrose',
'tempo', 'temps', 'thermal', 'tropic', 'turbid', 'twilight',
'viridis', 'ylgn', 'ylgnbu', 'ylorbr', 'ylorrd']
'viridis', 'ylgn', 'ylgnbu', 'ylorbr', 'ylorrd'].
Appending '_r' to a named colorscale reverses it.

Returns
-------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,8 @@ def colorscale(self):
'rdpu', 'rdylbu', 'rdylgn', 'redor', 'reds', 'solar', 'spectral',
'speed', 'sunset', 'sunsetdark', 'teal', 'tealgrn', 'tealrose',
'tempo', 'temps', 'thermal', 'tropic', 'turbid', 'twilight',
'viridis', 'ylgn', 'ylgnbu', 'ylorbr', 'ylorrd']
'viridis', 'ylgn', 'ylgnbu', 'ylorbr', 'ylorrd'].
Appending '_r' to a named colorscale reverses it.

Returns
-------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1413,7 +1413,8 @@ def colorscale(self):
'rdpu', 'rdylbu', 'rdylgn', 'redor', 'reds', 'solar', 'spectral',
'speed', 'sunset', 'sunsetdark', 'teal', 'tealgrn', 'tealrose',
'tempo', 'temps', 'thermal', 'tropic', 'turbid', 'twilight',
'viridis', 'ylgn', 'ylgnbu', 'ylorbr', 'ylorrd']
'viridis', 'ylgn', 'ylgnbu', 'ylorbr', 'ylorrd'].
Appending '_r' to a named colorscale reverses it.

Returns
-------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,8 @@ def colorscale(self):
'rdpu', 'rdylbu', 'rdylgn', 'redor', 'reds', 'solar', 'spectral',
'speed', 'sunset', 'sunsetdark', 'teal', 'tealgrn', 'tealrose',
'tempo', 'temps', 'thermal', 'tropic', 'turbid', 'twilight',
'viridis', 'ylgn', 'ylgnbu', 'ylorbr', 'ylorrd']
'viridis', 'ylgn', 'ylgnbu', 'ylorbr', 'ylorrd'].
Appending '_r' to a named colorscale reverses it.

Returns
-------
Expand Down
Loading