Skip to content

Commit 04295b2

Browse files
use geopandas built-in dataset
1 parent 05e4da6 commit 04295b2

File tree

4 files changed

+18
-25
lines changed

4 files changed

+18
-25
lines changed

doc/python/choropleth-maps.md

+6-10
Original file line numberDiff line numberDiff line change
@@ -166,23 +166,19 @@ fig.show()
166166

167167
### Using GeoPandas Data Frames
168168

169-
`px.choropleth` accepts the `geometry` of a GeoPandas data frame as the input to `geojson` if the `geometry` contains polygons.
169+
`px.choropleth` accepts the `geometry` of a [GeoPandas](https://geopandas.org/) data frame as the input to `geojson` if the `geometry` contains polygons.
170170

171171
```python
172172
import plotly.express as px
173173
import geopandas as gpd
174-
import wget
175174

176-
# download and load a zipped shapefile into a GeoDataFrame
177-
wget.download("https://plotly.github.io/datasets/nyc_boroughs.zip")
178-
geo_df = gpd.read_file("zip://nyc_boroughs.zip")
175+
geo_df = gpd.read_file(gpd.datasets.get_path('nybb')).to_crs("EPSG:4326")
179176

180-
181-
fig = px.choropleth(geo_df,
177+
fig = px.choropleth(geo_df,
182178
geojson=geo_df.geometry,
183-
locations=geo_df.index,
184-
color='shape_leng',
185-
hover_name="boro_name")
179+
locations=geo_df.index,
180+
color='Shape_Leng',
181+
hover_name="BoroName")
186182
fig.update_geos(fitbounds="locations", visible=False)
187183
fig.show()
188184
```

doc/python/mapbox-county-choropleth.md

+6-9
Original file line numberDiff line numberDiff line change
@@ -159,22 +159,19 @@ fig.show()
159159

160160
### Using GeoPandas Data Frames
161161

162-
`px.choropleth_mapbox` accepts the `geometry` of a GeoPandas data frame as the input to `geojson` if the `geometry` contains polygons.
162+
`px.choropleth_mapbox` accepts the `geometry` of a [GeoPandas](https://geopandas.org/) data frame as the input to `geojson` if the `geometry` contains polygons.
163163

164164
```python
165165
import plotly.express as px
166166
import geopandas as gpd
167-
import wget
168167

169-
# download and load a zipped shapefile into a GeoDataFrame
170-
wget.download("https://plotly.github.io/datasets/nyc_boroughs.zip")
171-
geo_df = gpd.read_file("zip://nyc_boroughs.zip")
168+
geo_df = gpd.read_file(gpd.datasets.get_path('nybb')).to_crs("EPSG:4326")
172169

173-
fig = px.choropleth_mapbox(geo_df,
170+
fig = px.choropleth_mapbox(geo_df,
174171
geojson=geo_df.geometry,
175-
locations=geo_df.index,
176-
color='shape_leng',
177-
hover_name="boro_name",
172+
locations=geo_df.index,
173+
color='Shape_Leng',
174+
hover_name="BoroName",
178175
center={"lat": 40.71, "lon": -74.00},
179176
mapbox_style="open-street-map",
180177
zoom=8)

doc/python/scatter-plots-on-maps.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ fig.show()
6868

6969
### Basic Example with GeoPandas
7070

71-
`px.scatter_geo` can work well with GeoPandas dataframes whose `geometry` is of type `Point`.
71+
`px.scatter_geo` can work well with [GeoPandas](https://geopandas.org/) dataframes whose `geometry` is of type `Point`.
7272

7373
```python
7474
import plotly.express as px
@@ -77,8 +77,8 @@ import geopandas as gpd
7777
geo_df = gpd.read_file(gpd.datasets.get_path('naturalearth_cities'))
7878

7979
px.set_mapbox_access_token(open(".mapbox_token").read())
80-
fig = px.scatter_geo(geo_df,
81-
lat=geo_df.geometry.y,
80+
fig = px.scatter_geo(geo_df,
81+
lat=geo_df.geometry.y,
8282
lon=geo_df.geometry.x,
8383
hover_name="name")
8484
fig.show()

doc/python/scattermapbox.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ fig.show()
5454

5555
### Basic Example with GeoPandas
5656

57-
`px.scatter_mapbox` can work well with GeoPandas dataframes whose `geometry` is of type `Point`.
57+
`px.scatter_mapbox` can work well with [GeoPandas](https://geopandas.org/) dataframes whose `geometry` is of type `Point`.
5858

5959
```python
6060
import plotly.express as px
@@ -63,8 +63,8 @@ import geopandas as gpd
6363
geo_df = gpd.read_file(gpd.datasets.get_path('naturalearth_cities'))
6464

6565
px.set_mapbox_access_token(open(".mapbox_token").read())
66-
fig = px.scatter_mapbox(geo_df,
67-
lat=geo_df.geometry.y,
66+
fig = px.scatter_mapbox(geo_df,
67+
lat=geo_df.geometry.y,
6868
lon=geo_df.geometry.x,
6969
hover_name="name",
7070
zoom=1)

0 commit comments

Comments
 (0)