Skip to content

Latest commit

 

History

History
143 lines (106 loc) · 5.82 KB

builtin-colorscales.md

File metadata and controls

143 lines (106 loc) · 5.82 KB
jupyter
jupytext kernelspec language_info plotly
notebook_metadata_filter text_representation
all
extension format_name format_version jupytext_version
.md
markdown
1.3
1.14.1
display_name language name
Python 3
python
python3
codemirror_mode file_extension mimetype name nbconvert_exporter pygments_lexer version
name version
ipython
3
.py
text/x-python
python
python
ipython3
3.8.8
description display_as has_thumbnail ipynb language layout name order permalink thumbnail v4upgrade
A reference for the built-in named continuous (sequential, diverging and cyclical) color scales in Plotly.
file_settings
true
~notebook_demo/187
python
base
Built-in Continuous Color Scales
28
python/builtin-colorscales/
thumbnail/heatmap_colorscale.jpg
true

Using Built-In Continuous Color Scales

Many Plotly Express functions accept a color_continuous_scale argument and many trace types have a colorscale attribute in their schema. Plotly comes with a large number of built-in continuous color scales, which can be referred to in Python code when setting the above arguments, either by name in a case-insensitive string e.g. px.scatter(color_continuous_scale="Viridis") or by reference e.g. go.Scatter(marker_colorscale=plotly.colors.sequential.Viridis). They can also be reversed by adding _r at the end e.g. "Viridis_r" or plotly.colors.sequential.Viridis_r.

The plotly.colours module is also available under plotly.express.colors so you can refer to it as px.colors.

When using continuous color scales, you will often want to configure various aspects of its range and colorbar.

Discrete Color Sequences

Plotly also comes with some built-in discrete color sequences which are not intended to be used with the color_continuous_scale argument as they are not designed for interpolation to occur between adjacent colors.

Named Built-In Continuous Color Scales

You can use any of the following names as string values to set continuous_color_scale or colorscale arguments. These strings are case-insensitive and you can append _r to them to reverse the order of the scale.

import plotly.express as px
from textwrap import wrap

named_colorscales = px.colors.named_colorscales()
print("\n".join(wrap("".join('{:<12}'.format(c) for c in named_colorscales), 96)))

Built-in color scales are stored as lists of CSS colors:

import plotly.express as px

print(px.colors.sequential.Plasma)

Continuous Color Scales in Dash

Dash is the best way to build analytical apps in Python using Plotly figures. To run the app below, run pip install dash, click "Download" to get the code and run python app.py.

Get started with the official Dash docs and learn how to effortlessly style & deploy apps like this with Dash Enterprise.

from IPython.display import IFrame
snippet_url = 'https://python-docs-dash-snippets.herokuapp.com/python-docs-dash-snippets/'
IFrame(snippet_url + 'builtin-colorscales', width='100%', height=1200)

Sign up for Dash Club → Free cheat sheets plus updates from Chris Parmer and Adam Schroeder delivered to your inbox every two months. Includes tips and tricks, community apps, and deep dives into the Dash architecture. Join now.

Built-In Sequential Color scales

A collection of predefined sequential colorscales is provided in the plotly.colors.sequential module. Sequential color scales are appropriate for most continuous data, but in some cases it can be helpful to use a diverging or cyclical color scale (see below).

Here are all the built-in scales in the plotly.colors.sequential module:

import plotly.express as px

fig = px.colors.sequential.swatches_continuous()
fig.show()

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

A collection of predefined diverging color scales is provided in the plotly.colors.diverging module. Diverging color scales are appropriate for continuous data that has a natural midpoint other otherwise informative special value, such as 0 altitude, or the boiling point of a liquid. These scales are intended to be used when explicitly setting the midpoint of the scale.

Here are all the built-in scales in the plotly.colors.diverging module:

import plotly.express as px

fig = px.colors.diverging.swatches_continuous()
fig.show()

Built-In Cyclical Color scales

A collection of predefined cyclical color scales is provided in the plotly.colors.cyclical module. Cyclical color scales are appropriate for continuous data that has a natural cyclical structure, such as temporal data (hour of day, day of week, day of year, seasons) or complex numbers or other phase or angular data.

Here are all the built-in scales in the plotly.colors.cyclical module:

import plotly.express as px

fig = px.colors.cyclical.swatches_cyclical()
fig.show()

fig = px.colors.cyclical.swatches_continuous()
fig.show()