folium.GeoJson(样式函数)无法正常工作
folium.GeoJson (style function) not working as i want
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
来使其工作
lambda x :{'fillColor':'green' if \
x['properties']['POP2005']<10000000 \
else 'orange' if 10000000 <x['properties']['POP2005']>20000000 else 'red'}
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
来使其工作
lambda x :{'fillColor':'green' if \
x['properties']['POP2005']<10000000 \
else 'orange' if 10000000 <x['properties']['POP2005']>20000000 else 'red'}