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/mapbox-county-choropleth.md
+36-34Lines changed: 36 additions & 34 deletions
Original file line number
Diff line number
Diff line change
@@ -6,9 +6,9 @@ jupyter:
6
6
extension: .md
7
7
format_name: markdown
8
8
format_version: '1.3'
9
-
jupytext_version: 1.14.1
9
+
jupytext_version: 1.16.3
10
10
kernelspec:
11
-
display_name: Python 3
11
+
display_name: Python 3 (ipykernel)
12
12
language: python
13
13
name: python3
14
14
language_info:
@@ -20,36 +20,32 @@ jupyter:
20
20
name: python
21
21
nbconvert_exporter: python
22
22
pygments_lexer: ipython3
23
-
version: 3.8.8
23
+
version: 3.10.0
24
24
plotly:
25
-
description: How to make a Mapbox Choropleth Map of US Counties in Python with
26
-
Plotly.
25
+
description: How to make a choropleth map of US counties in Python with Plotly.
27
26
display_as: maps
28
27
language: python
29
28
layout: base
30
-
name: Mapbox Choropleth Maps
29
+
name: Tile Choropleth Maps
31
30
order: 1
32
31
page_type: example_index
33
-
permalink: python/mapbox-county-choropleth/
32
+
permalink: python/tile-county-choropleth/
33
+
redirect_from: python/mapbox-county-choropleth/
34
34
thumbnail: thumbnail/mapbox-choropleth.png
35
35
---
36
36
37
-
A [Choropleth Map](https://en.wikipedia.org/wiki/Choropleth_map) is a map composed of colored polygons. It is used to represent spatial variations of a quantity. This page documents how to build **tile-map** choropleth maps, but you can also build [**outline** choropleth maps using our non-Mapbox trace types](/python/choropleth-maps).
37
+
A [Choropleth Map](https://en.wikipedia.org/wiki/Choropleth_map) is a map composed of colored polygons. It is used to represent spatial variations of a quantity. This page documents how to build **tile-map** choropleth maps, but you can also build [**outline** choropleth maps](/python/choropleth-maps).
38
38
39
-
Below we show how to create Choropleth Maps using either Plotly Express' `px.choropleth_mapbox` function or the lower-level `go.Choroplethmapbox` graph object.
40
-
41
-
#### Mapbox Access Tokens and Base Map Configuration
42
-
43
-
To plot on Mapbox maps with Plotly you _may_ need a Mapbox account and a public [Mapbox Access Token](https://www.mapbox.com/studio). See our [Mapbox Map Layers](/python/mapbox-layers/) documentation for more information.
39
+
Below we show how to create Choropleth Maps using either Plotly Express' `px.choropleth_map` function or the lower-level `go.Choroplethmap` graph object.
44
40
45
41
### Introduction: main parameters for choropleth tile maps
46
42
47
-
Making choropleth Mapbox maps requires two main types of input:
43
+
Making choropleth maps requires two main types of input:
48
44
49
45
1. GeoJSON-formatted geometry information where each feature has either an `id` field or some identifying value in `properties`.
50
46
2. A list of values indexed by feature identifier.
51
47
52
-
The GeoJSON data is passed to the `geojson` argument, and the data is passed into the `color` argument of `px.choropleth_mapbox` (`z` if using `graph_objects`), in the same order as the IDs are passed into the `location` argument.
48
+
The GeoJSON data is passed to the `geojson` argument, and the data is passed into the `color` argument of `px.choropleth_map` (`z` if using `graph_objects`), in the same order as the IDs are passed into the `location` argument.
53
49
54
50
**Note** the `geojson` attribute can also be the URL to a GeoJSON file, which can speed up map rendering in certain cases.
### Choropleth map using plotly.express and carto base map (no token needed)
76
+
### Choropleth map using plotly.express and carto base map
81
77
82
78
[Plotly Express](/python/plotly-express/) is the easy-to-use, high-level interface to Plotly, which [operates on a variety of types of data](/python/px-arguments/) and produces [easy-to-style figures](/python/styling-plotly-express/).
83
79
84
-
With `px.choropleth_mapbox`, each row of the DataFrame is represented as a region of the choropleth.
80
+
With `px.choropleth_map`, each row of the DataFrame is represented as a region of the choropleth.
`px.choropleth_mapbox` accepts the `geometry` of a [GeoPandas](https://geopandas.org/) data frame as the input to `geojson` if the `geometry` contains polygons.
175
+
`px.choropleth_map` accepts the `geometry` of a [GeoPandas](https://geopandas.org/) data frame as the input to `geojson` if the `geometry` contains polygons.
### Choropleth map using plotly.graph_objects and carto base map (no token needed)
196
+
### Choropleth map using plotly.graph_objects and carto base map
201
197
202
-
If Plotly Express does not provide a good starting point, it is also possible to use [the more generic `go.Choroplethmapbox` class from `plotly.graph_objects`](/python/graph-objects/).
198
+
If Plotly Express does not provide a good starting point, it is also possible to use [the more generic `go.Choroplethmap` class from `plotly.graph_objects`](/python/graph-objects/).
The earlier examples using `px.choropleth_map` and `go.Choroplethmap` use Maplibre for rendering. These traces were introduced in Plotly.py 5.24. These trace types are now the recommended way to create tile-based choropleth maps. There are also choropleth traces that use Mapbox: `px.choropleth_mapbox` and `go.Choroplethmapbox`
224
+
225
+
To plot on Mapbox maps with Plotly you _may_ need a Mapbox account and a public [Mapbox Access Token](https://www.mapbox.com/studio). See our [Mapbox Map Layers](/python/mapbox-layers/) documentation for more information.
226
+
227
+
Here's an exmaple of using the Mapbox Light base map, which requires a free token.
226
228
227
229
```python
228
230
token =open(".mapbox_token").read() # you will need your own token
229
231
230
-
231
232
from urllib.request import urlopen
232
233
import json
233
234
with urlopen('https://raw.githubusercontent.com/plotly/datasets/master/geojson-counties-fips.json') as response:
@@ -249,5 +250,6 @@ fig.show()
249
250
250
251
#### Reference
251
252
252
-
See [function reference for `px.(choropleth_mapbox)`](https://plotly.com/python-api-reference/generated/plotly.express.choropleth_mapbox) or https://plotly.com/python/reference/choroplethmapbox/ for more information about mapbox and their attribute options.
253
+
See [function reference for `px.(choropleth_map)`](https://plotly.com/python-api-reference/generated/plotly.express.choropleth_map) or https://plotly.com/python/reference/choroplethmap/ for more information about the attributes available.
253
254
255
+
For Mapbox-based tile maps, see [function reference for `px.(choropleth_mapbox)`](https://plotly.com/python-api-reference/generated/plotly.express.choropleth_mapbox) or https://plotly.com/python/reference/choroplethmapbox/.
0 commit comments