分区统计图未对区域进行着色

问题描述 投票:0回答:1

所以我之前制作了一张分区统计图并且它正在工作。这次我使用了相同的方法,但它不再显示了

map 和 unis_colleges 具有相同的形状和索引 地图和csv文件:text

#put a choropleth on top of the map 
m = folium.Map(location=[48.0196, 66.9237], tiles='cartodbpositron', zoom_start=6)
# Add a choropleth map to the base map

folium.Choropleth(geo_data=map.__geo_interface__, name = 'choropleth',
           data=student_total, columns = ['unis_colleges'],
           key_on="feature.id", 
           fill_color='YlGnBu', 
           legend_name='Number of students per region 2023').add_to(m)

# Display the map
m 
visualization geospatial folium choropleth
1个回答
0
投票

这很可能是 CRS 问题。我可以使用 this

.shp
文件(EPSG:3857 中投影)以及您提供的 the
.csv
文件重现您所描述的行为。所以,假设你所说的
map
最好将其命名为
gdf
)是
GeoDataFrame
,你可以这样做:

m = folium.Map(location=[48.0196, 66.9237], tiles="cartodbpositron", zoom_start=6)

folium.Choropleth(
    geo_data=gdf.to_crs("EPSG:4326").__geo_interface__,
    name="choropleth",
    data=student_total,
    columns=["regions", "unis_colleges"], # folium requires 2 columns
    key_on="feature.properties.ADM1_EN",  # replace ADM1_EN if needed
    fill_color="YlGnBu",
    legend_name="Number of students per region 2023",
).add_to(m)

输出(

m
):

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.