Choropleth映射未在python中显示,没有错误返回

时间:2019-03-28 11:05:16

标签: python json mapping choropleth

我为伦敦市镇创建了一个“伦敦”数据框,其中包含名称,人口和坐标。然后,我创建了一个大草坪地图,并添加了每个自治市镇的标记。运行得很好。但是,然后我尝试创建一个choropleth地图,显示每个行政区的人口密度。我使用IBM Watson Studio Python Notebook平台。

我在以下链接https://skgrange.github.io/www/data/london_boroughs.json中找到了伦敦自治市的geojson文件。它具有以下结构,具有“功能”列表,其中包含自治市镇数据及其坐标,依此类推。


{
  "type": "FeatureCollection",
  "crs": {
    "type": "name",
    "properties": {
      "name": "urn:ogc:def:crs:OGC:1.3:CRS84"
    }
  },
  "features": [
    {
      "type": "Feature",
      "id": 0,
      "properties": {
        "id": 1,
        "name": "Kingston upon Thames",
        "code": "E09000021",
        "area_hectares": 3726.117,
        "inner_statistical": 0
      },
      "geometry": {"type": "MultiPolygon", "coordinates": [] }
    },
    {
      "type": "Feature",
      "id": 23,
      "properties": {
        "id": 24,
        "name": "Kensington and Chelsea",
        "code": "E09000020",
        "area_hectares": 1238.379,
        "inner_statistical": 1
      },
      "geometry": {"type": "MultiPolygon","coordinates": [] }
}

我检查了数据框London ['Population'],它是浮动的。伦敦['Borough']中的所有自治市镇名称都与json文件中的名称匹配。

当我运行典型的Choropleth代码时,笔记本什么也没有显示。也没有错误消息出现。我尝试了一切,但并不真正知道可能是什么问题。 JSON文件错误?可能的话,您可以建议使用更好的json。请帮忙。

from geopy.geocoders import Nominatim
import folium

address = 'London'

geolocator = Nominatim(user_agent="ny_explorer")
location = geolocator.geocode(address)
latitude = location.latitude
longitude = location.longitude

map_london = folium.Map(location=[latitude, longitude], zoom_start=10, height = '70%', width = '70%')

# add markers to map
for lat, lng, borough in zip(London['Latitude'], London['Longitude'], London['Borough']):
    label = '{}'.format(borough)
    label = folium.Popup(label, parse_html=True)
    folium.CircleMarker(
        [lat, lng],
        radius=5,
        popup=label,
        color='blue',
        fill=True,
        fill_color='#3186cc',
        fill_opacity=0.7,
        parse_html=False).add_to(map_london)  

the above section worked perfectly well with beautiful London and borough markers shown.

!wget --quiet https://skgrange.github.io/www/data/london_boroughs.json -O london.json
london_geo = r'london.json'

map_london.choropleth(
 geo_data=london_geo,
 name='choropleth',
 data=London,
 columns=['Borough', 'Population'],
 key_on='Features.properties.name',
 fill_color='BuPu',
 fill_opacity=0.7,
 line_opacity=0.2,
 legend_name='Population rate of London Boroughs'
)
#Nothing appears here. No error message.

0 个答案:

没有答案