简体   繁体   中英

Choropleth Map of Sydney

I am trying to create a Choropleth map but it's not showing.

# Sydney latitude and longitude values
latitude = -33.892319
longitude = 151.146167

sydney_geo = r'suburb-2-nsw.json' # geojson file

sydney_map = folium.Map(location=[latitude, longitude], zoom_start=8, tiles='Mapbox Bright')

    sydney_map.choropleth(
    geo_data=sydney_geo,
    data=df_cities,
    columns=['city', 'count'],
    key_on='feature.properties.nsw_loca_2',
    fill_color='YlOrRd', 
    fill_opacity=0.7, 
    line_opacity=0.2,
    legend_name=''
)

# display map
sydney_map

I am using this geojson file - https://raw.githubusercontent.com/tonywr71/GeoJson-Data/master/suburb-2-nsw.geojson

And this is how the dataframe ( df_cities ) looks like -

在此处输入图片说明

I am just getting blank output -

在此处输入图片说明

Are you sure you are using the correct extension for your geojson file?

Using this code, it works:

import folium
import pandas as pd

# Sydney latitude and longitude values
latitude = -33.892319
longitude = 151.146167
m = folium.Map(location=[latitude, longitude],
               zoom_start=3,
               control_scale=True)

sydney_geo = r'suburb-2-nsw.geojson' # geojson file

df_cities = pd.DataFrame({'Unnamed':[2413, 815],
                          'city':['SIDNEY', 'DUBBO'],
                          'count':[593, 568]})

folium.Choropleth(geo_data=sydney_geo,
                  name='choropleth',
                  data=df_cities,
                  columns=['city', 'count'],
                  key_on='feature.properties.nsw_loca_2',
                  fill_color='YlOrRd',
                  fill_opacity=0.7,
                  line_opacity=0.2,
                  legend_name='In Debt').add_to(m)

folium.LayerControl().add_to(m)
m

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM