【问题标题】:How to deal with extreme values on a Folium map如何处理 Folium 地图上的极值
【发布时间】:2022-01-16 10:20:26
【问题描述】:

我对folium 地图的经验很少。 我需要用每个部门的机构数量制作一张地图,问题是首都的机构数量远远多于内部,所以当我创建颜色层时,我将首都设为深蓝色,其余的都一样较浅的颜色。这样地图就没那么有用了…… 我怎么能解决这个问题?我想也许将值除以人口,但最好使用原始值。 在文档中,我没有找到参数化颜色的方法。

    df1 = pd.DataFrame({'code':['75','77','78','91','92','93','94','95'],'value':['13000','2000','2500','2300','2150','2600','1630','1300']})
    dep_geo = geopandas.read_file('./dep.json', driver="JSON") #geodata taken from https://github.com/gregoiredavid/france-geojson/blob/master/departements.geojson
departments = {'75', '77', '78', '91', '92', '93', '94', '95'}
dep_geo = dep_geo[dep_geo['code'].isin(departments)]

df_map = dep_geo.merge(df1, how="left", left_on=['code'], right_on=['code'])

my_map = folium.Map(location=[48.856614, 2.3522219],
                    zoom_start = 9, tiles='cartodbpositron')

folium.Choropleth(
geo_data=df_map,
data=df_map,
columns=['code',"value"],
key_on="feature.properties.code",
fill_color='YlGnBu',
fill_opacity=0.5,
line_opacity=0.2,
legend_name="value ",
smooth_factor=0,
Highlight= True,
line_color = "black",
name = "value",
show=False,
overlay=True,
nan_fill_color = "White"
).add_to(my_map)

结果:

感谢您的帮助!

【问题讨论】:

    标签: python maps geopandas folium


    【解决方案1】:
    • 就像使用 vmax 参数一样简单。我已设置为第 85 个百分位
    • 还使用 geopandas explore() 生成 folium 地图
    import geopandas as gpd
    import pandas as pd
    import folium
    
    df1 = pd.DataFrame(
        {
            "code": ["75", "77", "78", "91", "92", "93", "94", "95"],
            "value": ["13000", "2000", "2500", "2300", "2150", "2600", "1630", "1300"],
        }
    )
    # dep_geo = geopandas.read_file('./dep.json', driver="JSON") #geodata taken from https://github.com/gregoiredavid/france-geojson/blob/master/departements.geojson
    dep_geo = gpd.read_file(
        "https://github.com/gregoiredavid/france-geojson/raw/master/departements.geojson"
    )  # geodata taken from https://github.com/gregoiredavid/france-geojson/blob/master/departements.geojson
    
    
    departments = {"75", "77", "78", "91", "92", "93", "94", "95"}
    dep_geo = dep_geo[dep_geo["code"].isin(departments)]
    df_map = dep_geo.merge(df1, how="left", left_on=["code"], right_on=["code"])
    df_map["value"] = pd.to_numeric(df_map["value"])
    
    df_map.explore(
        column="value",
        cmap="YlGnBu",
        vmax=df_map["value"].quantile(0.85),
        style_kwds=dict(
            color="rgba(0,0,0,.2)",
        ),
        location=[48.856614, 2.3522219],
        zoom_start=9,
        tiles="cartodbpositron",
    )
    

    【讨论】:

      猜你喜欢
      • 2022-09-28
      • 2022-09-28
      • 1970-01-01
      • 2022-12-03
      • 2019-11-24
      • 2018-10-16
      • 1970-01-01
      • 2012-09-13
      • 1970-01-01
      相关资源
      最近更新 更多