Skip to content

Commit b78ebd9

Browse files
final tweaks
1 parent f097c2d commit b78ebd9

File tree

3 files changed

+29
-62
lines changed

3 files changed

+29
-62
lines changed

python/filled-area-on-mapbox.md

+15-12
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jupyter:
66
extension: .md
77
format_name: markdown
88
format_version: '1.1'
9-
jupytext_version: 1.2.1
9+
jupytext_version: 1.1.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: How to make an area on Map in Python with Plotly.
2626
display_as: maps
@@ -36,18 +36,20 @@ jupyter:
3636
title: Python Mapbox Choropleth Maps | plotly
3737
---
3838

39+
<!-- #region -->
3940

4041
### Mapbox Access Token
4142

4243
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.
4344

4445

45-
### How to Show an Area on a Map
46+
There are three different ways to show a filled area in a Mapbox map:
47+
1. Use a [Scattermapbox](https://plot.ly/python/reference/#scattermapbox) trace and set `fill` attribute to 'toself'
48+
2. Use a Mapbox layout (i.e. by minimally using an empty [Scattermapbox](https://plot.ly/python/reference/#scattermapbox) trace) and add a GeoJSON layer
49+
3. Use the [Choroplethmapbox](https://plot.ly/python/mapbox-county-choropleth/) trace type
50+
<!-- #endregion -->
4651

47-
There are three different ways to show an area in a mapbox:
48-
- Use [Scattermapbox](https://plot.ly/python/reference/#scattermapbox) trace and set `fill` attribute to 'toself'
49-
- Use [Scattermapbox](https://plot.ly/python/reference/#scattermapbox) trace and define the corresponding geojson
50-
- Use the new trace type: [Choroplethmapbox](https://plot.ly/python/mapbox-county-choropleth/) for mapbox cases, or [Choropleth](https://plot.ly/python/choropleth-maps/) trace for non-mapbox ones.
52+
### Filled `Scattermapbox` Trace
5153

5254
The following example uses `Scattermapbox` and sets `fill = 'toself'`
5355

@@ -69,16 +71,17 @@ fig.update_layout(
6971
fig.show()
7072
```
7173

72-
### Provide Gaps on Map
74+
### Multiple Filled Areas with a `Scattermapbox` trace
7375

74-
The following example shows how to use missing values in your data to provide gap in your graph. To ignore the gap on your plot, take benefit of [connectorgaps](https://plot.ly/python/reference/#scattermapbox-connectgaps) attribute.
76+
The following example shows how to use `None` in your data to draw multiple filled areas. Such gaps in trace data are unconnected by default, but this can be controlled via the [connectgaps](https://plot.ly/python/reference/#scattermapbox-connectgaps) attribute.
7577

7678
```python
7779
import plotly.graph_objects as go
7880

7981
fig = go.Figure(go.Scattermapbox(
8082
mode = "lines", fill = "toself",
81-
lon = [-10, -10, 8, 8, None, 30, 30, 50, 50, None, 100, 100, 80, 80], lat = [30, 6, 6, 30, None, 20, 30, 30, 20, None, 40, 50, 50, 40]))
83+
lon = [-10, -10, 8, 8, -10, None, 30, 30, 50, 50, 30, None, 100, 100, 80, 80, 100],
84+
lat = [30, 6, 6, 30, 30, None, 20, 30, 30, 20, 20, None, 40, 50, 50, 40, 40]))
8285

8386
fig.update_layout(
8487
mapbox = {'style': "stamen-terrain", 'center': {'lon': 30, 'lat': 30}, 'zoom': 2},
@@ -88,9 +91,9 @@ fig.update_layout(
8891
fig.show()
8992
```
9093

91-
### Use the Corresponding Geojson
94+
### GeoJSON Layers
9295

93-
The second way is using Scattermapbox trace with the corresponding geojson.
96+
In this map we add a GeoJSON layer.
9497

9598
```python
9699
import plotly.graph_objects as go

python/lines-on-mapbox.md

+12-48
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jupyter:
66
extension: .md
77
format_name: markdown
88
format_version: '1.1'
9-
jupytext_version: 1.2.1
9+
jupytext_version: 1.1.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: How to draw a line on Map in Python with Plotly.
2626
display_as: maps
@@ -40,39 +40,30 @@ jupyter:
4040

4141
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.
4242

43-
### How to draw a Line on a Map
43+
To draw a line on your map, you either can use [`px.line_mapbox()`](https://www.plotly.express/plotly_express/#plotly_express.line_mapbox) in plotly express, or [`Scattermapbox`](https://plot.ly/python/reference/#scattermapbox) traces. Below we show you how to draw a line on Mapbox using plotly express.
4444

45-
To draw a line on your map, you either can use [line_mapbox](https://www.plotly.express/plotly_express/#plotly_express.line_mapbox) in plotly express, or [Scattermapbox](https://plot.ly/python/reference/#scattermapbox) and [scattergeo](https://plot.ly/python/reference/#scattergeo) trace type in plotly. Below we show you how to draw a line on Mapbox using plotly express.
45+
### Lines on Mapbox maps using Plotly Express
4646

4747
```python
4848
import pandas as pd
4949

50-
us_cities1 = pd.read_csv("https://raw.githubusercontent.com/plotly/datasets/master/us-cities-top-1k.csv")
51-
States = ['New York', 'Ohio']
52-
us_cities = us_cities1[us_cities1.State.isin(States)]
50+
us_cities = pd.read_csv("https://raw.githubusercontent.com/plotly/datasets/master/us-cities-top-1k.csv")
51+
us_cities = us_cities.query("State in ['New York', 'Ohio']")
5352

5453
import plotly.express as px
5554

56-
fig = px.line_mapbox(
57-
us_cities,
58-
lat="lat",
59-
lon="lon",
60-
line_group='State',
61-
hover_name="City",
62-
hover_data=["State", "Population"],
63-
color_discrete_sequence=["fuchsia"],
64-
zoom=3,
65-
height=300)
55+
fig = px.line_mapbox(us_cities, lat="lat", lon="lon", color="State", zoom=3, height=300)
6656

67-
fig.update_layout(
68-
mapbox_style="stamen-terrain", mapbox_zoom=4, mapbox_center_lat = 41,
57+
fig.update_layout(mapbox_style="stamen-terrain", mapbox_zoom=4, mapbox_center_lat = 41,
6958
margin={"r":0,"t":0,"l":0,"b":0})
7059

7160
fig.show()
7261
```
7362

74-
This example uses scattermapbox and defines
75-
the drawing [mode](https://plot.ly/python/reference/#scattermapbox-mode) to the combination of markers and line.
63+
### Lines on Mapbox maps using `Scattermapbox` traces
64+
65+
This example uses `go.Scattermapbox` and sets
66+
the [mode](https://plot.ly/python/reference/#scattermapbox-mode) attribute to a combination of markers and line.
7667

7768
```python
7869
import plotly.graph_objects as go
@@ -100,32 +91,5 @@ fig.update_layout(
10091
fig.show()
10192
```
10293

103-
This example uses scattermapbox trace and shows how to customize hoverinfo in Mapbox.
104-
105-
```python
106-
import pandas as pd
107-
108-
us_cities1 = pd.read_csv("https://raw.githubusercontent.com/plotly/datasets/master/us-cities-top-1k.csv")
109-
States = ['Washington']
110-
us_cities = us_cities1[us_cities1.State.isin(States)]
111-
112-
import plotly.graph_objects as go
113-
114-
fig = go.Figure(go.Scattermapbox(
115-
lat=us_cities.lat,
116-
lon=us_cities.lon,
117-
mode='markers+lines',
118-
marker={'color':'fuchsia', 'size':10, 'opacity':0.8},
119-
hovertext=us_cities['City'],
120-
hoverinfo='lat+lon+text'))
121-
122-
fig.update_layout(
123-
mapbox={'style': 'stamen-terrain', 'center':{'lat':47, 'lon':-117}, 'zoom':5},
124-
margin={"r":0,"t":0,"l":0,"b":0})
125-
126-
fig.show()
127-
128-
```
129-
13094
#### Reference
13195
See https://plot.ly/python/reference/#scattermapbox for more information about mapbox and their attribute options.

python/scattermapbox.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jupyter:
2020
name: python
2121
nbconvert_exporter: python
2222
pygments_lexer: ipython3
23-
version: 3.6.7
23+
version: 3.6.8
2424
plotly:
2525
description: How to make scatter plots on Mapbox maps in Python.
2626
display_as: maps
@@ -198,7 +198,7 @@ fig.show()
198198

199199
### Set Marker Symbols
200200

201-
You can define a symbol on your map by setting [symbol](https://plot.ly/python/reference/#scattermapbox-marker-symbol) attribute. This attribute only works on mapbox tiles (not work on raster tiles):
201+
You can define a symbol on your map by setting [symbol](https://plot.ly/python/reference/#scattermapbox-marker-symbol) attribute. This attribute only works on Mapbox-provided `style`s:
202202
- basic
203203
- streets
204204
- outdoors

0 commit comments

Comments
 (0)