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
12 changes: 8 additions & 4 deletions packages/python/plotly/_plotly_utils/basevalidators.py
Original file line number Diff line number Diff line change
Expand Up @@ -1558,7 +1558,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 +1576,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]
72 changes: 42 additions & 30 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 @@ -5533,8 +5534,7 @@ def points(self):
are shown and points either less than 4*Q1-3*Q3 or greater than
4*Q3-3*Q1 are highlighted (see `outliercolor`) If "all", all
sample points are shown If False, only the violins are shown
with no sample points and the whiskers extend to the range of the
sample.
with no sample points

The 'points' property is an enumeration that may be specified as:
- One of the following enumeration values:
Expand Down Expand Up @@ -6279,7 +6279,7 @@ def _prop_descriptions(self):
or greater than 4*Q3-3*Q1 are highlighted (see
`outliercolor`) If "all", all sample points are shown
If False, only the violins are shown with no sample
points and the whiskers extend to the range of the sample.
points
scalegroup
If there are multiple violins that should be sized
according to to some metric (see `scalemode`), link
Expand Down Expand Up @@ -6611,7 +6611,7 @@ def __init__(
or greater than 4*Q3-3*Q1 are highlighted (see
`outliercolor`) If "all", all sample points are shown
If False, only the violins are shown with no sample
points and the whiskers extend to the range of the sample.
points
scalegroup
If there are multiple violins that should be sized
according to to some metric (see `scalemode`), link
Expand Down Expand Up @@ -10331,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 @@ -14321,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 @@ -46589,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 @@ -49199,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 @@ -53650,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 @@ -56286,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 @@ -61006,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 @@ -62846,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 @@ -69238,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 @@ -71327,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 @@ -73294,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 @@ -75946,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 @@ -78056,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 @@ -79953,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 Expand Up @@ -84723,8 +84737,7 @@ def boxpoints(self):
are shown and points either less than 4*Q1-3*Q3 or greater than
4*Q3-3*Q1 are highlighted (see `outliercolor`) If "all", all
sample points are shown If False, only the box(es) are shown
with no sample points and the whiskers extend to the range of the
sample.
with no sample points

The 'boxpoints' property is an enumeration that may be specified as:
- One of the following enumeration values:
Expand Down Expand Up @@ -85990,7 +86003,7 @@ def _prop_descriptions(self):
or greater than 4*Q3-3*Q1 are highlighted (see
`outliercolor`) If "all", all sample points are shown
If False, only the box(es) are shown with no sample
points and the whiskers extend to the range of the sample.
points
customdata
Assigns extra data each datum. This may be useful when
listening to hover, click and selection events. Note
Expand Down Expand Up @@ -86296,7 +86309,7 @@ def __init__(
or greater than 4*Q3-3*Q1 are highlighted (see
`outliercolor`) If "all", all sample points are shown
If False, only the box(es) are shown with no sample
points and the whiskers extend to the range of the sample.
points
customdata
Assigns extra data each datum. This may be useful when
listening to hover, click and selection events. Note
Expand Down Expand Up @@ -95064,30 +95077,29 @@ def template(self):
annotation or a logo image, for example. To omit one of these
items on the plot, make an item with matching
`templateitemname` and `visible: false`.

The 'template' property is an instance of Template
that may be specified as:
- An instance of plotly.graph_objs.layout.Template
- A dict of string/value properties that will be passed
to the Template constructor

Supported dict properties:

data
plotly.graph_objects.layout.template.Data
instance or dict with compatible properties
layout
plotly.graph_objects.Layout instance or dict
with compatible properties

- The name of a registered template where current registered templates
are stored in the plotly.io.templates configuration object. The names
of all registered templates can be retrieved with:

>>> import plotly.io as pio
>>> list(pio.templates) # doctest: +ELLIPSIS
['ggplot2', 'seaborn', 'simple_white', 'plotly', 'plotly_white', 'plotly_dark', ...]

>>> list(pio.templates)
['ggplot2', 'seaborn', 'simple_white', 'plotly', 'plotly_white', 'plotly_dark', 'presentation', 'xgridoff', 'ygridoff', 'gridon', 'none']

- A string containing multiple registered template names, joined on '+'
characters (e.g. 'template1+template2'). In this case the resulting
Expand Down
Loading