我正在尝试使用 Geopandas 和 Matplotlib 在地图上显示商店的空间分布。问题: 当我绘制图钉时,底图会变形。这是绘制引脚之前和之后的示例问题: 这种失真的来源是什么?我该如何预防?import pandas as pdimport geopandas as gpdimport matplotlib.pyplot as pltfrom shapely.geometry import Polygon# Creating the simplified polygonlatitude = [60.41125, 59.99236, 59.99236]longitude = [24.66917, 24.66917, 25.36972]geometry = Polygon(zip(longitude, latitude))polygon = gpd.GeoDataFrame(index=[0], crs = 'epsg:4326', geometry=[geometry]) # ploting the basemapax = polygon.plot(color="#3791CB")# Dict of sample coordinatescoordinates = {"latitude": ["60.193141", "60.292777", "60.175053", "60.163187", "60.245272", "60.154392", "60.182906"],"longitude": ["24.934214", "24.969730", "24.831068", "24.739044", "24.860983", "24.884773", "24.959175"]}# Creating a dataframe from coordinatesdf = pd.DataFrame(coordinates)# Creating the GeoDataFrameshops = gpd.GeoDataFrame(coordinates, geometry=gpd.points_from_xy(df.longitude, df.latitude))# Plotting office coordinatesshops.plot(ax=ax, color="red", markersize = 20, zorder=2)# adding gridplt.grid(linestyle=":", color='grey')plt.show()谢谢你!
1 回答
哆啦的时光机
TA贡献1779条经验 获得超6个赞
你的地图和别针有不同的参考系统..
当您创建第一个 GeoDataFrame 时,您指定其坐标参考系统 (crs = 'epsg:4326')。当您为商店坐标创建地理数据框时,您不需要。这就是失真的来源……
这应该修复它:
shops = gpd.GeoDataFrame(
coordinates,
geometry = gpd.points_from_xy(
df.longitude,
df.latitude),
crs = "EPSG:4326"
)
)
添加回答
举报
0/150
提交
取消