【问题标题】:folium Choropleth world map: default values for countriesfolium Choropleth 世界地图:国家/地区的默认值
【发布时间】:2018-11-16 18:31:42
【问题描述】:

我正在使用GeoJSON world mapfolium to build a choropleth map

the_map = folium.Map(tiles="cartodbpositron")
the_map.choropleth(
    geo_data=country_shapes,
    name='choropleth',
    data=orders_by_country,
    columns=['country', 'orders'],
    key_on='feature.id',
    fill_color='Blues',
    fill_opacity=0.7,
    line_opacity=0.2,
)
the_map

我得到的结果显示所有未出现在数据框中的国家都以深蓝色阴影显示,这是最高值的颜色。为什么?可以设置默认值吗?

【问题讨论】:

  • 也许可以试试像BuGn 这样的调色板,而不是Blues
  • 不同的颜色,同样的问题。
  • 抱歉,这一项帮助不大。最好有某种默认颜色
  • 看看我的回答。我在尝试修改 folium quickstart 指南中的示例时遇到了同样的问题。

标签: python leaflet data-visualization geography folium


【解决方案1】:

您需要将您的 key_on 值更改为:key_on='feature.properties.name' 而不是 key_on='feature.id

假设您使用以下方法获取 country_shapes

url = 'https://raw.githubusercontent.com/python-visualization/folium/master/examples/data'
country_shapes = f'{url}/world-countries.json'

位于 github.com/python-visualization/folium/tree/master/examples/data/world-countries.json 的 json 文件中的字典的键确定您应该为 key_on 值使用什么。

即(来自world-countries.json):

{"type":"Feature","properties":{"name":"Afghanistan"},"geometry":{"type":"多边形","坐标":[[[61.210817,35.650072],...

根据folium documentation中的Choropleth类定义:

key_on (string, default None) – geo_data GeoJSON 文件中用于绑定数据的变量。必须以“功能”开头并使用 JavaScript 反对表示法。例如:
'feature.id' 或
‘feature.properties.statename’。

【讨论】:

    【解决方案2】:

    Folium 0.8 具有等值线图的新属性。请查看文档folium documentationnan_fill_color应该可以解决你的问题。

    the_map = folium.Map(tiles="cartodbpositron")
    the_map.choropleth(
        geo_data=country_shapes,
        name='choropleth',
        data=orders_by_country,
        columns=['country', 'orders'],
        key_on='feature.id',
        fill_color='Blues',
        nan_fill_color='white',
        fill_opacity=0.7,
        line_opacity=0.2,
    )
    the_map
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-04-25
      • 1970-01-01
      • 2013-01-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-20
      相关资源
      最近更新 更多