File tree 2 files changed +15
-10
lines changed
2 files changed +15
-10
lines changed Original file line number Diff line number Diff line change 6
6
extension : .md
7
7
format_name : markdown
8
8
format_version : ' 1.2'
9
- jupytext_version : 1.6.0
9
+ jupytext_version : 1.4.2
10
10
kernelspec :
11
11
display_name : Python 3
12
12
language : python
@@ -20,7 +20,7 @@ jupyter:
20
20
name : python
21
21
nbconvert_exporter : python
22
22
pygments_lexer : ipython3
23
- version : 3.7.6
23
+ version : 3.7.7
24
24
plotly :
25
25
description : How to make choropleth maps in Python with Plotly.
26
26
display_as : maps
@@ -184,13 +184,16 @@ fig.show()
184
184
import plotly.express as px
185
185
import geopandas as gpd
186
186
187
- geo_df = gpd.read_file(gpd.datasets.get_path(' nybb' )).to_crs(" EPSG:4326" )
187
+ df = px.data.election()
188
+ geo_df = gpd.GeoDataFrame.from_features(
189
+ px.data.election_geojson()[" features" ]
190
+ ).merge(df, on = " district" ).set_index(" district" )
188
191
189
192
fig = px.choropleth(geo_df,
190
193
geojson = geo_df.geometry,
191
194
locations = geo_df.index,
192
- color = ' Shape_Leng ' ,
193
- hover_name = " BoroName " )
195
+ color = " Joly " ,
196
+ projection = " mercator " )
194
197
fig.update_geos(fitbounds = " locations" , visible = False )
195
198
fig.show()
196
199
```
Original file line number Diff line number Diff line change @@ -165,16 +165,18 @@ fig.show()
165
165
import plotly.express as px
166
166
import geopandas as gpd
167
167
168
- geo_df = gpd.read_file(gpd.datasets.get_path(' nybb' )).to_crs(" EPSG:4326" )
168
+ df = px.data.election()
169
+ geo_df = gpd.GeoDataFrame.from_features(
170
+ px.data.election_geojson()[" features" ]
171
+ ).merge(df, on = " district" ).set_index(" district" )
169
172
170
173
fig = px.choropleth_mapbox(geo_df,
171
174
geojson = geo_df.geometry,
172
175
locations = geo_df.index,
173
- color = ' Shape_Leng' ,
174
- hover_name = " BoroName" ,
175
- center = {" lat" : 40.71 , " lon" : - 74.00 },
176
+ color = " Joly" ,
177
+ center = {" lat" : 45.5517 , " lon" : - 73.7073 },
176
178
mapbox_style = " open-street-map" ,
177
- zoom = 8 )
179
+ zoom = 8.5 )
178
180
fig.show()
179
181
```
180
182
You can’t perform that action at this time.
0 commit comments