【问题标题】:folium Choropleth colors showing grey onlyfolium Choropleth 颜色仅显示灰色
【发布时间】:2020-09-01 03:55:26
【问题描述】:

我正在尝试使用 folium choropleth 显示基于国家/地区的幸福水平,但是,它不起作用,所有国家/地区都只是灰色的。这就是我得到的:

json 文件:https://github.com/python-visualization/folium/blob/master/examples/data/world-countries.json

csv 文件:https://drive.google.com/file/d/1aI5tILdPYyx0yjbgPPZcJHEqxbZ4oPBg/view?usp=sharing

这是我的代码:

import folium
import pandas as pd


country_geo = 'world-countries.json'

country_data = pd.read_csv('Happiness_Dataset_2016.csv')

bins = list(country_data['Happiness Score'].quantile([0, 0.25, 0.5, 0.75, 1]))

m = folium.Map(location=[0,0], zoom_start=2)


folium.Choropleth(
    geo_data=country_geo,
    name='choropleth',
    data=country_data,
    columns=['Country','Happiness Score'],
    Key_on='feature.properties.name',
    fill_color='BuPu',
    fill_opacity=0.2,
    line_opacity=0.5,

    legend_name='Happiness Rates (%)',
    bins =bins,

    reset=True
).add_to(m)
# folium.LayerControl().add_to(m)
m
m.save('worldmap.html')

【问题讨论】:

  • 您好,欢迎您!您能否编辑您的帖子以包含代码围栏,并命名您的链接以便更容易理解?
  • 请提供完整的代码和数据。谢谢。
  • 我刚刚上传了 csv 和 json 文件链接。这就是我得到的所有代码,我只需要生成一个图像。

标签: python python-3.x pandas folium choropleth


【解决方案1】:

这里的错误:

Key_on='feature.properties.name',

修改为:

key_on='feature.properties.name',

你会得到:

【讨论】:

  • 哦,原来是这样!非常感谢!帮了我很多!
猜你喜欢
  • 2022-01-22
  • 1970-01-01
  • 2022-08-18
  • 1970-01-01
  • 2020-07-09
  • 2020-11-08
  • 2021-07-30
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多