diff --git a/CHANGELOG.md b/CHANGELOG.md index 60cda725b32..4624e7b5b87 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). - `go.Figure` now has a `set_subplots` method to set subplots on an already existing figure. +- Added `Turbo` colorscale ## [4.12.1] - UNRELEASED diff --git a/doc/python/builtin-colorscales.md b/doc/python/builtin-colorscales.md index 60c7fb873cd..1fede07a2d1 100644 --- a/doc/python/builtin-colorscales.md +++ b/doc/python/builtin-colorscales.md @@ -6,7 +6,7 @@ jupyter: extension: .md format_name: markdown format_version: '1.2' - jupytext_version: 1.3.1 + jupytext_version: 1.4.2 kernelspec: display_name: Python 3 language: python @@ -20,7 +20,7 @@ jupyter: name: python nbconvert_exporter: python pygments_lexer: ipython3 - version: 3.6.8 + version: 3.7.7 plotly: description: A reference for the built-in named continuous (sequential, diverging and cylclical) color scales in Plotly. @@ -83,11 +83,11 @@ Here are all the built-in scales in the `plotly.colors.sequential` module: ```python import plotly.express as px -fig = px.colors.sequential.swatches() +fig = px.colors.sequential.swatches_continuous() fig.show() ``` -Note: `RdBu` was included in this module by mistake, even though it is a diverging color scale. +Note: `RdBu` was included in the `sequential` module by mistake, even though it is a diverging color scale. It is intentionally left in for backwards-compatibility reasons. ### Built-In Diverging Color scales @@ -102,7 +102,7 @@ Here are all the built-in scales in the `plotly.colors.diverging` module: ```python import plotly.express as px -fig = px.colors.diverging.swatches().update_layout(margin_b=10) +fig = px.colors.diverging.swatches_continuous() fig.show() ``` @@ -121,6 +121,6 @@ import plotly.express as px fig = px.colors.cyclical.swatches_cyclical() fig.show() -fig = px.colors.cyclical.swatches() +fig = px.colors.cyclical.swatches_continuous() fig.show() -``` \ No newline at end of file +``` diff --git a/packages/python/plotly/_plotly_utils/colors/_swatches.py b/packages/python/plotly/_plotly_utils/colors/_swatches.py index 7c9b230c12c..95225629fb0 100644 --- a/packages/python/plotly/_plotly_utils/colors/_swatches.py +++ b/packages/python/plotly/_plotly_utils/colors/_swatches.py @@ -47,3 +47,115 @@ def _swatches(module_names, module_contents, template=None): margin=dict(b=10), ), ) + + +def _swatches_continuous(module_names, module_contents, template=None): + """ + 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) + for k, v in module_contents.items() + if not (k.startswith("_") or k.startswith("swatches") or k.endswith("_r")) + ] + + n = 100 + + return go.Figure( + data=[ + go.Bar( + orientation="h", + y=[name] * n, + x=[1] * n, + customdata=[(x + 1) / n for x in range(n)], + marker=dict(color=list(range(n)), colorscale=name, line_width=0), + hovertemplate="%{customdata}", + name=name, + ) + for name, colors in reversed(sequences) + ], + layout=dict( + title="plotly.colors." + module_names.split(".")[-1], + barmode="stack", + barnorm="fraction", + bargap=0.3, + showlegend=False, + xaxis=dict(range=[-0.02, 1.02], showticklabels=False, showgrid=False), + height=max(600, 40 * len(sequences)), + width=500, + template=args["template"], + margin=dict(b=10), + ), + ) + + +def _swatches_cyclical(module_names, module_contents, template=None): + """ + 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 polar bar charts. + """ + import plotly.graph_objects as go + from plotly.subplots import make_subplots + from plotly.express._core import apply_default_cascade + + args = dict(template=template) + apply_default_cascade(args) + + rows = 2 + cols = 4 + scales = [ + (k, v) + for k, v in module_contents.items() + if not (k.startswith("_") or k.startswith("swatches") or k.endswith("_r")) + ] + names = [name for name, colors in scales] + fig = make_subplots( + rows=rows, + cols=cols, + subplot_titles=names, + specs=[[{"type": "polar"}] * cols] * rows, + ) + + for i, (name, scale) in enumerate(scales): + fig.add_trace( + go.Barpolar( + r=[1] * int(360 / 5), + theta=list(range(0, 360, 5)), + marker_color=list(range(0, 360, 5)), + marker_cmin=0, + marker_cmax=360, + marker_colorscale=name, + name=name, + ), + row=int(i / cols) + 1, + col=i % cols + 1, + ) + fig.update_traces(width=5.2, marker_line_width=0, base=0.5, showlegend=False) + fig.update_polars(angularaxis_visible=False, radialaxis_visible=False) + fig.update_layout( + title="plotly.colors." + module_names.split(".")[-1], template=args["template"] + ) + return fig diff --git a/packages/python/plotly/_plotly_utils/colors/carto.py b/packages/python/plotly/_plotly_utils/colors/carto.py index 353579c9a70..919d7c99aa5 100644 --- a/packages/python/plotly/_plotly_utils/colors/carto.py +++ b/packages/python/plotly/_plotly_utils/colors/carto.py @@ -386,6 +386,6 @@ def swatches(template=None): # 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"): + if _k.startswith("_") or _k.startswith("swatches") or _k.endswith("_r"): continue globals()[_k + "_r"] = _cols[::-1] diff --git a/packages/python/plotly/_plotly_utils/colors/cmocean.py b/packages/python/plotly/_plotly_utils/colors/cmocean.py index 14734fc46bf..d5788712bb9 100644 --- a/packages/python/plotly/_plotly_utils/colors/cmocean.py +++ b/packages/python/plotly/_plotly_utils/colors/cmocean.py @@ -6,7 +6,7 @@ cmocean is made available under an MIT license: https://github.com/matplotlib/cmocean/blob/master/LICENSE.txt """ -from ._swatches import _swatches +from ._swatches import _swatches, _swatches_continuous def swatches(template=None): @@ -15,6 +15,14 @@ def swatches(template=None): swatches.__doc__ = _swatches.__doc__ + +def swatches_continuous(template=None): + return _swatches_continuous(__name__, globals(), template) + + +swatches_continuous.__doc__ = _swatches_continuous.__doc__ + + turbid = [ "rgb(232, 245, 171)", "rgb(220, 219, 137)", @@ -271,6 +279,6 @@ def swatches(template=None): # 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"): + if _k.startswith("_") or _k.startswith("swatches") or _k.endswith("_r"): continue globals()[_k + "_r"] = _cols[::-1] diff --git a/packages/python/plotly/_plotly_utils/colors/colorbrewer.py b/packages/python/plotly/_plotly_utils/colors/colorbrewer.py index 2b1714bf0f1..9e3098144b3 100644 --- a/packages/python/plotly/_plotly_utils/colors/colorbrewer.py +++ b/packages/python/plotly/_plotly_utils/colors/colorbrewer.py @@ -460,6 +460,6 @@ def swatches(template=None): # 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"): + if _k.startswith("_") or _k.startswith("swatches") or _k.endswith("_r"): continue globals()[_k + "_r"] = _cols[::-1] diff --git a/packages/python/plotly/_plotly_utils/colors/cyclical.py b/packages/python/plotly/_plotly_utils/colors/cyclical.py index bab6fdfc4ff..2cd1cead1a7 100644 --- a/packages/python/plotly/_plotly_utils/colors/cyclical.py +++ b/packages/python/plotly/_plotly_utils/colors/cyclical.py @@ -4,7 +4,7 @@ complex numbers or other phase data. """ -from ._swatches import _swatches +from ._swatches import _swatches, _swatches_continuous, _swatches_cyclical def swatches(template=None): @@ -14,54 +14,18 @@ def swatches(template=None): swatches.__doc__ = _swatches.__doc__ +def swatches_continuous(template=None): + return _swatches_continuous(__name__, globals(), template) + + +swatches_continuous.__doc__ = _swatches_continuous.__doc__ + + def swatches_cyclical(template=None): - """ - 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 polar bar charts. - """ - import plotly.graph_objects as go - from plotly.subplots import make_subplots - from plotly.express._core import apply_default_cascade - - args = dict(template=template) - apply_default_cascade(args) - - rows = 2 - cols = 4 - scales = ["Twilight", "IceFire", "Edge", "Phase", "HSV", "mrybm", "mygbm"] - fig = make_subplots( - rows=rows, - cols=cols, - subplot_titles=scales, - specs=[[{"type": "polar"}] * cols] * rows, - ) - - for i, scale in enumerate(scales): - fig.add_trace( - go.Barpolar( - r=[1] * int(360 / 5), - theta=list(range(0, 360, 5)), - marker_color=list(range(0, 360, 5)), - marker_cmin=0, - marker_cmax=360, - marker_colorscale=scale, - name=scale, - ), - row=int(i / cols) + 1, - col=i % cols + 1, - ) - fig.update_traces(width=5.2, marker_line_width=0, base=0.5, showlegend=False) - fig.update_polars(angularaxis_visible=False, radialaxis_visible=False) - fig.update_layout(title="plotly.colors.cyclical", template=args["template"]) - return fig + return _swatches_cyclical(__name__, globals(), template) + + +swatches_cyclical.__doc__ = _swatches_cyclical.__doc__ Twilight = [ diff --git a/packages/python/plotly/_plotly_utils/colors/diverging.py b/packages/python/plotly/_plotly_utils/colors/diverging.py index 2e20a4fd8b5..92d6d72f139 100644 --- a/packages/python/plotly/_plotly_utils/colors/diverging.py +++ b/packages/python/plotly/_plotly_utils/colors/diverging.py @@ -17,12 +17,12 @@ RdYlGn, Spectral, ) -from .cmocean import balance, delta, curl # noqa: F401 +from .cmocean import balance, delta, curl, oxy # noqa: F401 from .carto import Armyrose, Fall, Geyser, Temps, Tealrose, Tropic, Earth # noqa: F401 from .plotlyjs import Picnic, Portland # noqa: F401 -from ._swatches import _swatches +from ._swatches import _swatches, _swatches_continuous def swatches(template=None): @@ -31,10 +31,17 @@ def swatches(template=None): swatches.__doc__ = _swatches.__doc__ + +def swatches_continuous(template=None): + return _swatches_continuous(__name__, globals(), template) + + +swatches_continuous.__doc__ = _swatches_continuous.__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"): + if _k.startswith("_") or _k.startswith("swatches") or _k.endswith("_r"): continue globals()[_k + "_r"] = _cols[::-1] diff --git a/packages/python/plotly/_plotly_utils/colors/plotlyjs.py b/packages/python/plotly/_plotly_utils/colors/plotlyjs.py index feb2cc9965a..0d8cd9944a4 100644 --- a/packages/python/plotly/_plotly_utils/colors/plotlyjs.py +++ b/packages/python/plotly/_plotly_utils/colors/plotlyjs.py @@ -183,6 +183,6 @@ # 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"): + if _k.startswith("_") or _k.startswith("swatches") or _k.endswith("_r"): continue globals()[_k + "_r"] = _cols[::-1] diff --git a/packages/python/plotly/_plotly_utils/colors/qualitative.py b/packages/python/plotly/_plotly_utils/colors/qualitative.py index 41fe43fc3d6..ff8430f4695 100644 --- a/packages/python/plotly/_plotly_utils/colors/qualitative.py +++ b/packages/python/plotly/_plotly_utils/colors/qualitative.py @@ -149,7 +149,7 @@ def swatches(template=None): # 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"): + if _k.startswith("_") or _k.startswith("swatches") or _k.endswith("_r"): continue globals()[_k + "_r"] = _cols[::-1] diff --git a/packages/python/plotly/_plotly_utils/colors/sequential.py b/packages/python/plotly/_plotly_utils/colors/sequential.py index bc408e47deb..50d77eaaac1 100644 --- a/packages/python/plotly/_plotly_utils/colors/sequential.py +++ b/packages/python/plotly/_plotly_utils/colors/sequential.py @@ -5,7 +5,7 @@ mostly meant to be passed in as the `color_continuous_scale` argument to various functions. """ -from ._swatches import _swatches +from ._swatches import _swatches, _swatches_continuous def swatches(template=None): @@ -14,6 +14,13 @@ def swatches(template=None): swatches.__doc__ = _swatches.__doc__ + +def swatches_continuous(template=None): + return _swatches_continuous(__name__, globals(), template) + + +swatches_continuous.__doc__ = _swatches_continuous.__doc__ + Plotly3 = [ "#0508b8", "#1910d8", @@ -91,7 +98,23 @@ def swatches(template=None): "#fdca26", "#f0f921", ] - +Turbo = [ + "#30123b", + "#4145ab", + "#4675ed", + "#39a2fc", + "#1bcfd4", + "#24eca6", + "#61fc6c", + "#a4fc3b", + "#d1e834", + "#f3c63a", + "#fe9b2d", + "#f36315", + "#d93806", + "#b11901", + "#7a0402", +] from .plotlyjs import Blackbody, Bluered, Electric, Hot, Jet, Rainbow # noqa: F401 from .colorbrewer import ( # noqa: F401 @@ -159,7 +182,7 @@ def swatches(template=None): # 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"): + if _k.startswith("_") or _k.startswith("swatches") or _k.endswith("_r"): continue globals()[_k + "_r"] = _cols[::-1]