[英]Choropleth map with folium - python
Im having trouble to do choropleth map for brazil state Im using folium library to do it as follows: 我在使用巴西文库执行以下操作时无法对巴西状态的Choropleth映射进行操作:
import folium
import json
with open('br-states.json') as json_data:
d = json.load(json_data)
m = folium.Map(
location=[-18.826592, -55.212558],
zoom_start=4,
tiles='OpenStreetMap')
m.choropleth(
geo_data=d,
name='choropleth',
data=new_data,
columns=['State', 'QTY'],
key_on='feature.id',
fill_color='YlGn',
fill_opacity=0.7,
line_opacity=0.2,
legend_name='Unemployment Rate (%)'
)
folium.LayerControl().add_to(m)
m
My data is called new_data
我的数据叫做
new_data
I dont know if there is some problem with the code or there is problem with my json
file called br-state
(might be related to the coordinates used by the autor of this file or something else) 我不知道代码是否存在问题或我的
json
文件(称为br-state
存在问题(可能与该文件的指导者使用的坐标有关或其他原因)
I get the map however the map does not turn to choropleth map 我得到了地图,但是地图没有变成choropleth地图
Any suggetion will be highly appreciated 任何建议将不胜感激
I am using this JSON file: https://github.com/datalivre/Conjunto-de-Dados/blob/master/br_states.json Look at the code, it's a bit different from yours. 我正在使用以下JSON文件: https : //github.com/datalivre/Conjunto-de-Dados/blob/master/br_states.json查看代码,它与您的代码有些不同。 You do not need to convert the JSON file to a dictionary.
您无需将JSON文件转换为字典。 Here an image with the result that I got.
这是我得到的结果的图像。 folium br_states
br_states叶
import folium
import pandas as pd
new_data = pd.read_excel('new_data.xlsx')
state_geo = 'br_states.json'
mapa = folium.Map(
location=[-15.77972, -47.92972],
zoom_start=3
)
folium.Choropleth(
geo_data=state_geo,
name='Estados QTY',
data=new_data,
columns=['State','QTY'],
key_on='feature.id',
fill_color='YlOrBr',
fill_opacity=0.7,
line_opacity=0.1,
legend_name='Insert legend'
).add_to(mapa)
folium.LayerControl().add_to(mapa)
mapa.save('index.html')
mapa
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.