File tree Expand file tree Collapse file tree 3 files changed +18
-13
lines changed Expand file tree Collapse file tree 3 files changed +18
-13
lines changed Original file line number Diff line number Diff line change 66 extension : .md
77 format_name : markdown
88 format_version : ' 1.2'
9- jupytext_version : 1.6.0
9+ jupytext_version : 1.4.2
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.6
23+ version : 3.7.7
2424 plotly :
2525 description : How to make choropleth maps in Python with Plotly.
2626 display_as : maps
@@ -184,13 +184,16 @@ fig.show()
184184import plotly.express as px
185185import geopandas as gpd
186186
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" )
188191
189192fig = px.choropleth(geo_df,
190193 geojson = geo_df.geometry,
191194 locations = geo_df.index,
192- color = ' Shape_Leng ' ,
193- hover_name = " BoroName " )
195+ color = " Joly " ,
196+ projection = " mercator " )
194197fig.update_geos(fitbounds = " locations" , visible = False )
195198fig.show()
196199```
Original file line number Diff line number Diff line change @@ -165,16 +165,18 @@ fig.show()
165165import plotly.express as px
166166import geopandas as gpd
167167
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" )
169172
170173fig = px.choropleth_mapbox(geo_df,
171174 geojson = geo_df.geometry,
172175 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 },
176178 mapbox_style = " open-street-map" ,
177- zoom = 8 )
179+ zoom = 8.5 )
178180fig.show()
179181```
180182
Original file line number Diff line number Diff line change @@ -9,9 +9,9 @@ patsy==0.5.1
99numpy == 1.16.0
1010plotly-geo
1111python-igraph
12- geopandas
13- pyshp
14- shapely
12+ geopandas == 0.8.1
13+ pyshp == 2.1.2
14+ shapely == 1.7.1
1515psutil
1616requests
1717networkx
You can’t perform that action at this time.
0 commit comments