You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/python/builtin-colorscales.md
+16-17
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@ jupyter:
5
5
text_representation:
6
6
extension: .md
7
7
format_name: markdown
8
-
format_version: '1.2'
8
+
format_version: "1.2"
9
9
jupytext_version: 1.3.1
10
10
kernelspec:
11
11
display_name: Python 3
@@ -22,40 +22,39 @@ jupyter:
22
22
pygments_lexer: ipython3
23
23
version: 3.6.8
24
24
plotly:
25
-
description: A reference for the built-in named continuous (sequential, diverging
26
-
and cylclical) colorscales in Plotly.
25
+
description:
26
+
A reference for the built-in named continuous (sequential, diverging
27
+
and cylclical) color scales in Plotly.
27
28
display_as: file_settings
28
29
has_thumbnail: true
29
30
ipynb: ~notebook_demo/187
30
31
language: python
31
32
layout: base
32
-
name: Built-in Continuous Colorscales
33
+
name: Built-in Continuous Color Scales
33
34
order: 27
34
35
permalink: python/builtin-colorscales/
35
36
thumbnail: thumbnail/heatmap_colorscale.jpg
36
37
v4upgrade: true
37
38
---
38
39
39
-
### Using Built-In Continuous Colorscales
40
+
### Using Built-In Continuous Color Scales
40
41
41
42
Many Plotly Express functions accept a `color_continuous_scale` argument and many trace
42
43
types have a `colorscale` attribute in their schema. Plotly comes with a large number of
43
-
built-in continuous colorscales, which can be referred to in Python code when setting the above arguments,
44
+
built-in continuous color scales, which can be referred to in Python code when setting the above arguments,
44
45
either by name in a case-insensitive string e.g. `px.scatter(continuous_color_scale="Viridis"`) or by reference e.g.
45
46
`go.Scatter(marker_colorscale=plotly.colors.sequential.Viridis)`. They can also be reversed by adding `_r` at the end
46
47
e.g. `"Viridis_r"` or `plotly.colors.sequential.Viridis_r`.
47
48
48
49
The `plotly.colours` module is also available under `plotly.express.colors` so you can refer to it as `px.colors`.
49
50
50
-
When using continuous colorscales, you will often want to [configure various aspects of its range and colorbar](/python/colorscales/).
51
+
When using continuous color scales, you will often want to [configure various aspects of its range and colorbar](/python/colorscales/).
51
52
53
+
### Discrete Color Sequences
52
54
53
-
### Categorical Color Sequences
55
+
Plotly also comes with some built-in [discrete color sequences](/python/discrete-color/) 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.
54
56
55
-
Plotly also comes with some built-in [categorical color sequences](/python/categorical-color/) 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.
56
-
57
-
58
-
### Named Built-In Colorscales
57
+
### Named Built-In Continuous Color Scales
59
58
60
59
You can use any of the following names as string values to set `continuous_color_scale` or `colorscale` arguments.
61
60
These strings are case-insensitive and you can append `_r` to them to reverse the order of the scale.
@@ -76,7 +75,7 @@ import plotly.express as px
76
75
print(px.colors.sequential.Plasma)
77
76
```
78
77
79
-
### Built-In Sequential Colorscales
78
+
### Built-In Sequential Color scales
80
79
81
80
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).
82
81
@@ -92,9 +91,9 @@ fig.show()
92
91
Note: `RdBu` was included in this module by mistake, even though it is a diverging color scale.
93
92
It is intentionally left in for backwards-compatibility reasons.
94
93
95
-
### Built-In Diverging Colorscales
94
+
### Built-In Diverging Color scales
96
95
97
-
A collection of predefined diverging colorscales is provided in the `plotly.colors.diverging` module.
96
+
A collection of predefined diverging color scales is provided in the `plotly.colors.diverging` module.
98
97
Diverging color scales are appropriate for continuous data that has a natural midpoint
99
98
other otherwise informative special value, such as 0 altitude, or the boiling point
100
99
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).
Copy file name to clipboardExpand all lines: doc/python/colorscales.md
+30-31
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@ jupyter:
5
5
text_representation:
6
6
extension: .md
7
7
format_name: markdown
8
-
format_version: '1.2'
8
+
format_version: "1.2"
9
9
jupytext_version: 1.3.1
10
10
kernelspec:
11
11
display_name: Python 3
@@ -22,7 +22,8 @@ jupyter:
22
22
pygments_lexer: ipython3
23
23
version: 3.6.8
24
24
plotly:
25
-
description: How to set, create and control continous color scales and color bars
25
+
description:
26
+
How to set, create and control continous color scales and color bars
26
27
in scatter, bar, map and heatmap figures.
27
28
display_as: file_settings
28
29
has_thumbnail: true
@@ -37,31 +38,29 @@ jupyter:
37
38
v4upgrade: true
38
39
---
39
40
40
-
### Continuous vs Categorical Color
41
-
42
-
In the same way as the X or Y position of a mark in cartesian coordinates can be used to represent continuous values (i.e. amounts or moments in time) or categories (i.e. labels), color can be used to represent continuous or categorical data. This page is about using color to represent **continuous** data, but Plotly can also [represent categorical values with color](/python/categorical-color/).
41
+
### Continuous vs Discrete Color
43
42
43
+
In the same way as the X or Y position of a mark in cartesian coordinates can be used to represent continuous values (i.e. amounts or moments in time) or categories (i.e. labels), color can be used to represent continuous or categorical data. This page is about using color to represent **continuous** data, but Plotly can also [represent categorical values with color](/python/discrete-color/).
44
44
45
45
### Continuous Color Concepts
46
46
47
47
This document explains the following four continuous-color-related concepts:
48
48
49
-
-**color scales** represent a mapping between the range 0 to 1 and some color domain within which colors are to be interpolated (unlike [categorical color sequences](/python/categorical-color/) which are never interpolated). Color scale defaults depend on the `layout.colorscales` attributes of the active [template](/python/templates/), and can be explicitly specified using the `color_continuous_scale` argument for many [Plotly Express](/python/plotly-express/) functions or the `colorscale` argument in various `graph_objects` such as `layout.coloraxis` or `marker.colorscale` in `go.Scatter` traces or `colorscale` in `go.Heatmap` traces. For example `[(0,"blue"), (1,"red")]` is a simple color scale that interpolated between blue and red via purple, which can also be implicitly represented as `["blue", "red"]` and happens to be one of the [built-in color scales](/python/builtin-colorscales) and therefore referred to as `"bluered"` or `plotly.colors.sequential.Bluered`.
49
+
-**color scales** represent a mapping between the range 0 to 1 and some color domain within which colors are to be interpolated (unlike [discrete color sequences](/python/discrete-color/) which are never interpolated). Color scale defaults depend on the `layout.colorscales` attributes of the active [template](/python/templates/), and can be explicitly specified using the `color_continuous_scale` argument for many [Plotly Express](/python/plotly-express/) functions or the `colorscale` argument in various `graph_objects` such as `layout.coloraxis` or `marker.colorscale` in `go.Scatter` traces or `colorscale` in `go.Heatmap` traces. For example `[(0,"blue"), (1,"red")]` is a simple color scale that interpolated between blue and red via purple, which can also be implicitly represented as `["blue", "red"]` and happens to be one of the [built-in color scales](/python/builtin-colorscales) and therefore referred to as `"bluered"` or `plotly.colors.sequential.Bluered`.
50
50
-**color ranges** represent the minimum to maximum range of data to be mapped onto the 0 to 1 input range of the color scale. Color ranges default to the range of the input data and can be explicitly specified using either the `range_color` or `color_continous_midpoint` arguments for many Plotly Express functions, or `cmin`/`cmid`/`cmax` or `zmin`/`zmid`/`zmax` for various `graph_objects` such as `layout.coloraxis.cmin` or `marker.cmin` in `go.Scatter` traces or `cmin` in `go.Heatmap` traces. For example, if a color range of `[100, 200]` is used with the color scale above, then any mark with a color value of 100 or less will be blue, and 200 or more will be red. Marks with values in between will be various shades of purple.
51
51
-**color bars** are legend-like visible representations of the color range and color scale with optional tick labels and tick marks. Color bars can be configured with attributes inside `layout.coloraxis.colorbar` or in places like `marker.colorbar` in `go.Scatter` traces or `colorbar` in `go.Heatmap` traces.
52
52
-**color axes** connect color scales, color ranges and color bars to a trace's data. By default, any colorable attribute in a trace is attached to its own local color axis, but color axes may also be shared across attributes and traces by setting e.g. `marker.coloraxis` in `go.Scatter` traces or `coloraxis` in `go.Heatmap` traces. Local color axis attributes are configured within traces e.g. `marker.showscale` whereas shared color axis attributes are configured within the Layout e.g. `layout.coloraxis.showscale`.
53
53
54
-
55
54
### Continuous Color with Plotly Express
56
55
57
-
Most Plotly Express functions accept a `color` argument which automatically assigns data values to continuous color **if the data is numeric**. If the data contains strings, the color will automatically be considered [discrete (also known as categorical or qualitative)](/python/categorical-color/). This means that numeric strings must be parsed to be used for continuous color, and conversely, numbers used as category codes must be converted to strings.
56
+
Most Plotly Express functions accept a `color` argument which automatically assigns data values to continuous color **if the data is numeric**. If the data contains strings, the color will automatically be considered [discrete (also known as categorical or qualitative)](/python/discrete-color/). This means that numeric strings must be parsed to be used for continuous color, and conversely, numbers used as category codes must be converted to strings.
58
57
59
58
For example, in the `tips` dataset, the `size` column contains numbers:
title="Numeric 'size' values mean continous color")
91
90
92
91
fig.show()
93
92
```
94
93
95
94
### Color Scales in Plotly Express
96
95
97
-
By default, Plotly Express will use the color scale from the active [template](/python/templates/)'s `layout.colorscales.sequential` attribute, and the default active template is `plotly` which uses the `Plasma` color scale. You can choose any of the [built-in colorscales](/python/builtin-colorscales/), however, or define your own.
96
+
By default, Plotly Express will use the color scale from the active [template](/python/templates/)'s `layout.colorscales.sequential` attribute, and the default active template is `plotly` which uses the `Plasma` color scale. You can choose any of the [built-in color scales](/python/builtin-colorscales/), however, or define your own.
98
97
99
-
Here is an example that creates a scatter plot using Plotly Express, with points colored using the Viridis colorscale.
98
+
Here is an example that creates a scatter plot using Plotly Express, with points colored using the Viridis color scale.
You can reverse a [built-in colorscale](/python/builtin-colorscales/) by appending `_r` to its name, for colorscales given either as a string or a `plotly` object.
122
+
You can reverse a [built-in color scale](/python/builtin-colorscales/) by appending `_r` to its name, for color scales given either as a string or a `plotly` object.
The Plotly Express `color_continuous_scale` argument accepts explicitly-constructed colorscales as well:
144
+
The Plotly Express `color_continuous_scale` argument accepts explicitly-constructed color scales as well:
146
145
147
146
```python
148
147
import plotly.express as px
@@ -166,7 +165,7 @@ fig.show()
166
165
167
166
### Constructing a Discrete or Discontinuous Color Scale
168
167
169
-
You can create a discrete color scale, with discontinuous color, by setting the same reference point twice in a row. This is useful for example with chart types that don't support categorical colors, like [Parallel Coordinates plots](/python/parallel-coordinates-plot/). See below for how to customize tick text.
168
+
You can create a discrete color scale, with discontinuous color, by setting the same reference point twice in a row. This is useful for example with chart types that don't support discrete colors, like [Parallel Coordinates plots](/python/parallel-coordinates-plot/). See below for how to customize tick text.
### Setting the Midpoint of a Color Range for a Diverging Colorscale
192
+
### Setting the Midpoint of a Color Range for a Diverging Color scale
194
193
195
-
Diverging colorscales have a well-defined midpoint color, and are best-used when that midpoint is mapped to a meaningful data value. The `color_continuous_midpoint` argument to most Plotly Express functions is used for this. It cannot be used with `range_color` because setting it forces the color range to be centered on the midpoint while including the entire dataset. This means that for asymmetric data distributions, not all colors in the color scale will appear in the figure.
194
+
Diverging color scales have a well-defined midpoint color, and are best-used when that midpoint is mapped to a meaningful data value. The `color_continuous_midpoint` argument to most Plotly Express functions is used for this. It cannot be used with `range_color` because setting it forces the color range to be centered on the midpoint while including the entire dataset. This means that for asymmetric data distributions, not all colors in the color scale will appear in the figure.
196
195
197
-
For example, a diverging colorscale could be used to highlight points with a higher and lower value than the median in a choropleth map like this:
196
+
For example, a diverging color scale could be used to highlight points with a higher and lower value than the median in a choropleth map like this:
### Custom Discretized Heatmap Colorscale with Graph Objects
285
+
### Custom Discretized Heatmap Color scale with Graph Objects
287
286
288
287
```python
289
288
import plotly.graph_objects as go
@@ -337,7 +336,7 @@ fig.add_trace(go.Heatmap(
337
336
fig.show()
338
337
```
339
338
340
-
### Colorscale for Scatter Plots with Graph Objects
339
+
### Color scale for Scatter Plots with Graph Objects
341
340
342
341
```python
343
342
import plotly.graph_objects as go
@@ -365,7 +364,7 @@ fig.add_trace(go.Scatter(
365
364
fig.show()
366
365
```
367
366
368
-
### Colorscale for Contour Plot with Graph Objects
367
+
### Color scale for Contour Plot with Graph Objects
369
368
370
369
```python
371
370
import plotly.graph_objects as go
@@ -384,7 +383,7 @@ fig.add_trace(go.Contour(
384
383
fig.show()
385
384
```
386
385
387
-
### Custom Heatmap Colorscale with Graph Objects
386
+
### Custom Heatmap Color scale with Graph Objects
388
387
389
388
```python
390
389
import plotly.graph_objects as go
@@ -417,7 +416,7 @@ fig.add_trace(go.Heatmap(
417
416
fig.show()
418
417
```
419
418
420
-
### Setting the Midpoint of a Diverging Colorscale with Graph Objects
419
+
### Setting the Midpoint of a Diverging Color scale with Graph Objects
421
420
422
421
The following example uses the [marker.cmid](https://plot.ly/python/reference/#scatter-marker-cmid) attribute to set the mid-point of the color domain by scaling 'cmin' and/or 'cmax' to be equidistant to this point. It only has impact when [marker.color](https://plot.ly/python/reference/#scattercarpet-marker-line-color) sets to a numerical array, and 'marker.cauto' is `True`.
423
422
@@ -450,7 +449,7 @@ fig = go.Figure(go.Heatmap(
450
449
fig.show()
451
450
```
452
451
453
-
### Custom Contour Plot Colorscale with Graph Objects
452
+
### Custom Contour Plot Color scale with Graph Objects
454
453
455
454
```python
456
455
import plotly.graph_objects as go
@@ -474,9 +473,9 @@ fig.add_trace(go.Contour(
474
473
fig.show()
475
474
```
476
475
477
-
### Custom Colorbar Title, Labels, and Ticks with Graph Objects
476
+
### Custom Color bar Title, Labels, and Ticks with Graph Objects
478
477
479
-
Like axes, you can customize the colorbar ticks, labels, and values with `ticks`, `ticktext`, and `tickvals`.
478
+
Like axes, you can customize the color bar ticks, labels, and values with `ticks`, `ticktext`, and `tickvals`.
0 commit comments