python - 在 Geopandas 中绘图时管理投影
问题描述
我正在使用 geopandas 绘制意大利地图。
import matplotlib.pyplot as plt
fig, ax = plt.subplots(figsize = (20,30))
region_map.plot(ax=ax, color='white', edgecolor='black')
plt.xlim([6,19])
plt.ylim([36,47.7])
plt.tight_layout()
plt.show()
这就是在正确定义region_map
为“几何” GeoSeries 之后的结果。
但是,我无法修改图形纵横比,即使figsize
在plt.subplots
. 我错过了一些微不足道的事情,还是可能是地理熊猫问题?
谢谢
解决方案
您的源数据集 ( region_map
) 显然是在地理坐标系中“编码”的(单位:lats 和 lons)。在您的情况下可以安全地假设这是 WGS84 (EPSG: 4326 )。如果您希望您的绘图看起来更像它在例如谷歌地图中的样子,您将不得不将其坐标重新投影到许多投影坐标系之一(单位:米)。您可以使用全球可接受的 WEB MERCATOR (EPSG: 3857 )。
Geopandas 让这一切变得尽可能简单。您只需要了解我们如何处理计算机科学中的坐标投影并通过其 EPSG 代码学习最流行的 CRS 的基础知识。
import matplotlib.pyplot as plt
#If your source does not have a crs assigned to it, do it like this:
region_map.crs = {"init": "epsg:4326"}
#Now that Geopandas what is the "encoding" of your coordinates, you can perform any coordinate reprojection
region_map = region_map.to_crs(epsg=3857)
fig, ax = plt.subplots(figsize = (20,30))
region_map.plot(ax=ax, color='white', edgecolor='black')
#Keep in mind that these limits are not longer referring to the source data!
# plt.xlim([6,19])
# plt.ylim([36,47.7])
plt.tight_layout()
plt.show()
我强烈建议阅读有关管理预测的官方 GeoPandas 文档。
推荐阅读
- jquery - 通过单击动态更改引导程序上的网格模式
- java - 如何使用MongoRepository接口从spring mongo中的数组中获取指定的对象字段
- android - 如何制作一个倒圆角的矩形?
- c# - 如何更改菜单项边框颜色?
- c# - 如何使用 c# 使用计时器运行不同的进程
- c# - 如何增加 UWP 日历日期选择器的高度?
- javascript - 根据单击的切换按钮更改 DIV 内容
- java - 如何在 Spring 中验证泛型类型
- multidimensional-array - 从 PowerDesigner 中的 SAP HANA 计算视图对物理数据模型进行逆向工程
- javascript - 角。如果值为 false,则在 textarea 中为数组对象添加下划线