Skip to content

Commit e9117dd

Browse files
categorical to discrete
1 parent 94bef10 commit e9117dd

File tree

3 files changed

+62
-66
lines changed

3 files changed

+62
-66
lines changed

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

+16-17
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ jupyter:
55
text_representation:
66
extension: .md
77
format_name: markdown
8-
format_version: '1.2'
8+
format_version: "1.2"
99
jupytext_version: 1.3.1
1010
kernelspec:
1111
display_name: Python 3
@@ -22,40 +22,39 @@ jupyter:
2222
pygments_lexer: ipython3
2323
version: 3.6.8
2424
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.
2728
display_as: file_settings
2829
has_thumbnail: true
2930
ipynb: ~notebook_demo/187
3031
language: python
3132
layout: base
32-
name: Built-in Continuous Colorscales
33+
name: Built-in Continuous Color Scales
3334
order: 27
3435
permalink: python/builtin-colorscales/
3536
thumbnail: thumbnail/heatmap_colorscale.jpg
3637
v4upgrade: true
3738
---
3839

39-
### Using Built-In Continuous Colorscales
40+
### Using Built-In Continuous Color Scales
4041

4142
Many Plotly Express functions accept a `color_continuous_scale` argument and many trace
4243
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,
4445
either by name in a case-insensitive string e.g. `px.scatter(continuous_color_scale="Viridis"`) or by reference e.g.
4546
`go.Scatter(marker_colorscale=plotly.colors.sequential.Viridis)`. They can also be reversed by adding `_r` at the end
4647
e.g. `"Viridis_r"` or `plotly.colors.sequential.Viridis_r`.
4748

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

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/).
5152

53+
### Discrete Color Sequences
5254

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.
5456

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
5958

6059
You can use any of the following names as string values to set `continuous_color_scale` or `colorscale` arguments.
6160
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
7675
print(px.colors.sequential.Plasma)
7776
```
7877

79-
### Built-In Sequential Colorscales
78+
### Built-In Sequential Color scales
8079

8180
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).
8281

@@ -92,9 +91,9 @@ fig.show()
9291
Note: `RdBu` was included in this module by mistake, even though it is a diverging color scale.
9392
It is intentionally left in for backwards-compatibility reasons.
9493

95-
### Built-In Diverging Colorscales
94+
### Built-In Diverging Color scales
9695

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.
9897
Diverging color scales are appropriate for continuous data that has a natural midpoint
9998
other otherwise informative special value, such as 0 altitude, or the boiling point
10099
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).
@@ -108,9 +107,9 @@ fig = px.colors.diverging.swatches()
108107
fig.show()
109108
```
110109

111-
### Built-In Cyclical Colorscales
110+
### Built-In Cyclical Color scales
112111

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

Diff for: doc/python/colorscales.md

+30-31
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ jupyter:
55
text_representation:
66
extension: .md
77
format_name: markdown
8-
format_version: '1.2'
8+
format_version: "1.2"
99
jupytext_version: 1.3.1
1010
kernelspec:
1111
display_name: Python 3
@@ -22,7 +22,8 @@ jupyter:
2222
pygments_lexer: ipython3
2323
version: 3.6.8
2424
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
2627
in scatter, bar, map and heatmap figures.
2728
display_as: file_settings
2829
has_thumbnail: true
@@ -37,31 +38,29 @@ jupyter:
3738
v4upgrade: true
3839
---
3940

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
4342

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/).
4444

4545
### Continuous Color Concepts
4646

4747
This document explains the following four continuous-color-related concepts:
4848

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`.
5050
- **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.
5151
- **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.
5252
- **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`.
5353

54-
5554
### Continuous Color with Plotly Express
5655

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.
5857

5958
For example, in the `tips` dataset, the `size` column contains numbers:
6059

6160
```python
6261
import plotly.express as px
6362
df = px.data.tips()
64-
fig = px.scatter(df, x="total_bill", y="tip", color="size",
63+
fig = px.scatter(df, x="total_bill", y="tip", color="size",
6564
title="Numeric 'size' values mean continous color")
6665

6766
fig.show()
@@ -73,7 +72,7 @@ Converting this column to strings is very straightforward:
7372
import plotly.express as px
7473
df = px.data.tips()
7574
df["size"] = df["size"].astype(str)
76-
fig = px.scatter(df, x="total_bill", y="tip", color="size",
75+
fig = px.scatter(df, x="total_bill", y="tip", color="size",
7776
title="String 'size' values mean discrete colors")
7877

7978
fig.show()
@@ -86,17 +85,17 @@ import plotly.express as px
8685
df = px.data.tips()
8786
df["size"] = df["size"].astype(str)
8887
df["size"] = df["size"].astype(float)
89-
fig = px.scatter(df, x="total_bill", y="tip", color="size",
88+
fig = px.scatter(df, x="total_bill", y="tip", color="size",
9089
title="Numeric 'size' values mean continous color")
9190

9291
fig.show()
9392
```
9493

9594
### Color Scales in Plotly Express
9695

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.
9897

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.
10099

101100
```python
102101
import plotly.express as px
@@ -107,7 +106,7 @@ fig = px.scatter(df, x="sepal_width", y="sepal_length",
107106
fig.show()
108107
```
109108

110-
It is also possible to specify colorscales by name. Here is an example that specifies the `Inferno` colorscale by name, as a string
109+
It is also possible to specify color scales by name. Here is an example that specifies the `Inferno` color scale by name, as a string
111110

112111
```python
113112
import plotly.express as px
@@ -118,9 +117,9 @@ fig = px.scatter(df, x="sepal_width", y="sepal_length",
118117
fig.show()
119118
```
120119

121-
### Reversing a built-in colorscale
120+
### Reversing a built-in color scale
122121

123-
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.
124123

125124
```python
126125
import plotly.express as px
@@ -140,9 +139,9 @@ fig = px.imshow(data, color_continuous_scale=px.colors.sequential.Cividis_r)
140139
fig.show()
141140
```
142141

143-
### Explicity Constructing a Colorscale
142+
### Explicity Constructing a Color scale
144143

145-
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:
146145

147146
```python
148147
import plotly.express as px
@@ -166,7 +165,7 @@ fig.show()
166165

167166
### Constructing a Discrete or Discontinuous Color Scale
168167

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.
170169

171170
```python
172171
import plotly.express as px
@@ -190,11 +189,11 @@ fig = px.scatter(df, x="sepal_width", y="sepal_length", color="sepal_length", ra
190189
fig.show()
191190
```
192191

193-
### Setting the Midpoint of a Color Range for a Diverging Colorscale
192+
### Setting the Midpoint of a Color Range for a Diverging Color scale
194193

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.
196195

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:
198197

199198
```python
200199
import plotly.express as px
@@ -283,7 +282,7 @@ fig.update_layout(coloraxis_colorbar=dict(
283282
fig.show()
284283
```
285284

286-
### Custom Discretized Heatmap Colorscale with Graph Objects
285+
### Custom Discretized Heatmap Color scale with Graph Objects
287286

288287
```python
289288
import plotly.graph_objects as go
@@ -337,7 +336,7 @@ fig.add_trace(go.Heatmap(
337336
fig.show()
338337
```
339338

340-
### Colorscale for Scatter Plots with Graph Objects
339+
### Color scale for Scatter Plots with Graph Objects
341340

342341
```python
343342
import plotly.graph_objects as go
@@ -365,7 +364,7 @@ fig.add_trace(go.Scatter(
365364
fig.show()
366365
```
367366

368-
### Colorscale for Contour Plot with Graph Objects
367+
### Color scale for Contour Plot with Graph Objects
369368

370369
```python
371370
import plotly.graph_objects as go
@@ -384,7 +383,7 @@ fig.add_trace(go.Contour(
384383
fig.show()
385384
```
386385

387-
### Custom Heatmap Colorscale with Graph Objects
386+
### Custom Heatmap Color scale with Graph Objects
388387

389388
```python
390389
import plotly.graph_objects as go
@@ -417,7 +416,7 @@ fig.add_trace(go.Heatmap(
417416
fig.show()
418417
```
419418

420-
### Setting the Midpoint of a Diverging Colorscale with Graph Objects
419+
### Setting the Midpoint of a Diverging Color scale with Graph Objects
421420

422421
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`.
423422

@@ -450,7 +449,7 @@ fig = go.Figure(go.Heatmap(
450449
fig.show()
451450
```
452451

453-
### Custom Contour Plot Colorscale with Graph Objects
452+
### Custom Contour Plot Color scale with Graph Objects
454453

455454
```python
456455
import plotly.graph_objects as go
@@ -474,9 +473,9 @@ fig.add_trace(go.Contour(
474473
fig.show()
475474
```
476475

477-
### Custom Colorbar Title, Labels, and Ticks with Graph Objects
476+
### Custom Color bar Title, Labels, and Ticks with Graph Objects
478477

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`.
480479

481480
```python
482481
import plotly.graph_objects as go
@@ -527,7 +526,7 @@ fig.update_layout(coloraxis = {'colorscale':'viridis'})
527526
fig.show()
528527
```
529528

530-
### Logarithmic Colorscale with Graph Objects
529+
### Logarithmic Color scale with Graph Objects
531530

532531
```python
533532
import plotly.graph_objects as go

0 commit comments

Comments
 (0)