Skip to content

Commit be25a7b

Browse files
adding built-in colorscales reference page
1 parent 6669d3e commit be25a7b

File tree

2 files changed

+110
-2
lines changed

2 files changed

+110
-2
lines changed

Diff for: doc/python/builtin-colorscales.md

+108
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
---
2+
jupyter:
3+
jupytext:
4+
notebook_metadata_filter: all
5+
text_representation:
6+
extension: .md
7+
format_name: markdown
8+
format_version: "1.2"
9+
jupytext_version: 1.3.0
10+
kernelspec:
11+
display_name: Python 3
12+
language: python
13+
name: python3
14+
language_info:
15+
codemirror_mode:
16+
name: ipython
17+
version: 3
18+
file_extension: .py
19+
mimetype: text/x-python
20+
name: python
21+
nbconvert_exporter: python
22+
pygments_lexer: ipython3
23+
version: 3.7.3
24+
plotly:
25+
description: A reference for the built-in named continuous (sequential, diverging and cylclical) colorscales in Plotly.
26+
display_as: file_settings
27+
has_thumbnail: true
28+
ipynb: ~notebook_demo/187
29+
language: python
30+
layout: base
31+
name: Built-in Continuous Colorscales
32+
order: 26
33+
permalink: python/builtin-colorscales/
34+
thumbnail: thumbnail/heatmap_colorscale.jpg
35+
v4upgrade: true
36+
---
37+
38+
### Using Built-In Colorscales
39+
40+
Many Plotly Express functions accept a `color_continuous_scale` argument and many trace
41+
types have a `colorscale` attribute in their schema. Plotly comes with a large number of
42+
built-in continuous colorscales, which can be referred to in Python code when setting the above arguments,
43+
either by name in a case-insensitive string e.g. `px.scatter(continuous_color_scale="Viridis"`) or by reference e.g.
44+
`go.Scatter(marker_colorscale=plotly.colors.sequential.Viridis)`. They can also be reversed by adding `_r` at the end
45+
e.g. `"Viridis_r"` or `plotly.colors.sequential.Viridis_r`.
46+
47+
The `plotly.colours` module is also available under `plotly.express.colors` so you can refer to it as `px.colors`.
48+
49+
When using continuous colorscales, you will often want to [configure various aspects of its range and colorbar](/python/colorscales/).
50+
51+
### Named Built-In Colorscales
52+
53+
You can use any of the following names as string values to set `continuous_color_scale` or `colorscale` arguments.
54+
These strings are case-insensitive and you can append `_r` to them to reverse the order of the scale.
55+
56+
```python
57+
import plotly.express as px
58+
59+
print("".join('{:<12}'.format(c) for c in px.colors.named_colorscales()))
60+
```
61+
62+
### Built-In Sequential Colorscales
63+
64+
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).
65+
66+
Here are all the built-in scales in the `plotly.colors.sequential` module:
67+
68+
```python
69+
import plotly.express as px
70+
71+
fig = px.colors.sequential.swatches()
72+
fig.show()
73+
```
74+
75+
Note: `RdBu` was included in this module by mistake, even though it is a diverging color scale.
76+
It is intentionally left in for backwards-compatibility reasons.
77+
78+
### Built-In Diverging Colorscales
79+
80+
A collection of predefined diverging colorscales is provided in the `plotly.colors.diverging` module.
81+
Diverging color scales are appropriate for continuous data that has a natural midpoint
82+
other otherwise informative special value, such as 0 altitude, or the boiling point
83+
of a liquid. These scales are intended to be used when [explicitly setting the midpoint of the scale](/python/colorscales/#setting-the-midpoint-of-a-diverging-colorscale).
84+
85+
Here are all the built-in scales in the `plotly.colors.diverging` module:
86+
87+
```python
88+
import plotly.express as px
89+
90+
fig = px.colors.diverging.swatches()
91+
fig.show()
92+
```
93+
94+
### Built-In Cyclical Colorscales
95+
96+
A collection of predefined cyclical colorscales is provided in the `plotly.colors.cyclical` module.
97+
Cyclical color scales are appropriate for continuous data that has a natural cyclical
98+
structure, such as temporal data (hour of day, day of week, day of year, seasons) or
99+
complex numbers or other phase or angular data.
100+
101+
Here are all the built-in scales in the `plotly.colors.cyclical` module:
102+
103+
```python
104+
import plotly.express as px
105+
106+
fig = px.colors.cyclical.swatches()
107+
fig.show()
108+
```

Diff for: doc/python/colorscales.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jupyter:
66
extension: .md
77
format_name: markdown
88
format_version: "1.2"
9-
jupytext_version: 1.3.0
9+
jupytext_version: 1.3.1
1010
kernelspec:
1111
display_name: Python 3
1212
language: python
@@ -20,7 +20,7 @@ jupyter:
2020
name: python
2121
nbconvert_exporter: python
2222
pygments_lexer: ipython3
23-
version: 3.7.3
23+
version: 3.6.8
2424
plotly:
2525
description:
2626
How to set colorscales and heatmap colorscales in Python and Plotly.

0 commit comments

Comments
 (0)