folium.GeoJson(样式功能)不能按我的要求工作 [英] folium.GeoJson (style function) not working as i want

查看:97
本文介绍了folium.GeoJson(样式功能)不能按我的要求工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

import folium ,pandas ,json

df=pandas.read_csv('Volcanoes_2.txt')

def colors(elev):
    minimum=int(min(df['ELEV']))
    step=int(max((df['ELEV'])-min(df['ELEV']))/3)
    if elev in range (minimum,minimum+step):
        col= "green"
    elif elev in range(minimum+step,minimum+step*2):
        col= "orange"
    else:
        col= "red"
    return col


map_1=folium.Map(location=[df['LAT'].mean(), df['LON'].mean()] ,
zoom_start=6,tiles='mapbox bright')

for name, lon, lat, elev in zip(df['NAME'], df['LON'], df['LAT'],
df['ELEV'] ):
    folium.Marker([lat, lon], popup= name,
     icon = folium.Icon(color =colors(elev))).add_to(map_1)

folium.GeoJson(open('world_geojson.json'),
           name='geojson',
           style_function= lambda x :{'fillcolor':'green' if \
  x['properties']['POP2005']<10000000 \
       else 'orange' if 10000000 <x['properties']['POP2005']>20000000 else 'red'},
       ).add_to(map_1)

folium.LayerControl().add_to(map_1)

map_1.save("map.html")

这是地图文件 https://github.com/xxspider4/new_repo /blob/master/map.html

这是json文件 https://github.com/xxspider4/new_repo /blob/master/world_geojson.json

推荐答案

您非常亲密.我可以通过将样式功能中的fillcolor更改为fillColor来使其工作

You were very close. I was able to get it to work by changing fillcolor to fillColor in your style function

lambda x :{'fillColor':'green' if \ x['properties']['POP2005']<10000000 \ else 'orange' if 10000000 <x['properties']['POP2005']>20000000 else 'red'}

lambda x :{'fillColor':'green' if \ x['properties']['POP2005']<10000000 \ else 'orange' if 10000000 <x['properties']['POP2005']>20000000 else 'red'}

这篇关于folium.GeoJson(样式功能)不能按我的要求工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆