Python 为什么Folium以单一颜色呈现颜色?

Python 为什么Folium以单一颜色呈现颜色?,python,folium,choropleth,Python,Folium,Choropleth,警告-我是Folium的新手,因此任何帮助都将不胜感激。。。我正试图为南美洲创造一个人口密度高的国家。我有以下数据: idx id pop_den location 0 AR 16.177 Argentina 1 BO 10.202 Bolivia 2 BR 25.040 Brazil 3 CL 24.282 Chile 4 CO 44.223 Colombia 5 EC 66.939 Ecuador 6 GY 3.952 Guyana

警告-我是Folium的新手,因此任何帮助都将不胜感激。。。我正试图为南美洲创造一个人口密度高的国家。我有以下数据:

idx id  pop_den location
0   AR  16.177  Argentina
1   BO  10.202  Bolivia
2   BR  25.040  Brazil
3   CL  24.282  Chile
4   CO  44.223  Colombia
5   EC  66.939  Ecuador
6   GY  3.952   Guyana
7   PY  17.144  Paraguay
8   PE  25.129  Peru
9   SR  3.612   Suriname
10  UY  19.751  Uruguay
11  VE  36.253  Venezuela
这是要在geo.json文件中读取的代码

sa_geojson = geopandas.read_file('continent_South_America_subunits.json')

该文件的示例如下:

{
"type": "FeatureCollection",
"features": [
{ "type": "Feature","id":"AR", "properties": { "scalerank": 0, "featurecla": "Admin-0 map subunit", "labelrank": 2.000000, "sovereignt": "Argentina", "sov_a3": "ARG", "adm0_dif": 0.000000, "level": 2.000000, "type": "Sovereign country", "admin": "Argentina", "adm0_a3": "ARG", "geou_dif": 0.000000, "geounit": "Argentina", "gu_a3": "ARG", "su_dif": 0.000000, "subunit": "Argentina", "su_a3": "ARG", "brk_diff": 0.000000, "name": "Argentina", "name_long": "Argentina", "brk_a3": "ARG", "brk_name": "Argentina", "brk_group": "", "abbrev": "Arg.", "postal": "AR", "formal_en": "Argentine Republic", "formal_fr": "", "note_adm0": "", "note_brk": "", "name_sort": "Argentina", "name_alt": "", "mapcolor7": 3.000000, "mapcolor8": 1.000000, "mapcolor9": 3.000000, "mapcolor13": 13.000000, "pop_est": 40913584.000000, "gdp_md_est": 573900.000000, "pop_year": -99.000000, "lastcensus": 2010.000000, "gdp_year": -99.000000, "economy": "5. Emerging region: G20", "income_grp": "3. Upper middle income", "wikipedia": -99.000000, "fips_10": "", "iso_a2": "AR", "iso_a3": "ARG", "iso_n3": "032", "un_a3": "032", "wb_a2": "AR", "wb_a3": "ARG", "woe_id": -99.000000, "adm0_a3_is": "ARG", "adm0_a3_us": "ARG", "adm0_a3_un": -99.000000, "adm0_a3_wb": -99.000000, "continent": "South America", "region_un": "Americas", "subregion": "South America", "region_wb": "Latin America & Caribbean", "name_len": 9.000000, "long_len": 9.000000, "abbrev_len": 4.000000, "tiny": -99.000000, "homepart": 1.000000 }, "geometry": { "type": "MultiPolygon", "coordinates": [ [ [ [ -68.654124, -54.886244 ], [ -68.654135, -54.886245 ], [ -68.654135, -54.886244 ], [ -68.642343, -54.853653 ], [ -68.641988, -54.799174 ],

这是构建地图和覆盖Choropleth的代码

## Build the Map for South America

map = flm.Map(location = [-22.5,-56.5], zoom_start = 2.5)

flm.Choropleth (
    geo_data = sa_geojson,
    name = "choropleth",
    date = cvd_tot_sa1,
    columns = ["id", "population_density"],
    key_on = "feature.id",
    fill_color = "YlGn",
    fill_opacity = 0.7,
    legend_name = "population density",
).add_to(map)

flm.LayerControl().add_to(map)
map
它给我的输出是

我已经阅读了帖子,确保json和数据文件中的
id
是相同的,并检查了json文件中的lat和long是否正确,以确保映射到正确的位置

任何建议都会很有帮助-提前thx

  • Python-3.7.9
  • 叶-0.12.1

    • 您的错误只是一个打字错误。为数据指定的参数名为“data”。第一次启动库时,有很多关于数据结构以及如何将其与数据绑定的知识需要学习。你可能已经花了很多时间来解决这个问题,但它肯定会在未来以巨大的结果的形式回到你的身边。祝你好运

      map = flm.Map(location = [-22.5,-56.5], zoom_start = 2.5)
      
      flm.Choropleth (
          geo_data = sa_geojson,
          name = "choropleth",
          data = cvd_tot_sa1, # date->data
          columns = ["id", "population_density"],
          key_on = "feature.id",
          fill_color = "YlGn",
          fill_opacity = 0.7,
          legend_name = "population density",
      ).add_to(map)
      
      flm.LayerControl().add_to(map)
      map
      

      感谢您的帮助,您肯定发现了我遇到的一个问题(准确的代码/键入…)。我现在得到了图例栏,它离我更近了,但是整个图形仍然是不透明的黑色,这是整个南美洲的单一颜色。我可以打开和关闭该层,因此它似乎是该层的一个问题,只有该层-仍然悬而未决。如果您有一个geojson文件,您可能能够更具体地澄清该问题。