在Geopandas中绘图时管理投影

6号

我正在使用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之后的结果

意大利地图

但是,我无法修改人物的纵横比,甚至改变figsizeplt.subplots我是否错过了一些琐碎的事情,或者这可能是大熊猫的问题?

谢谢

玛莉安·摩德

您的源数据集(region_map)显然已在地理坐标系中“编码” (单位:经度和纬度)。可以安全地假设这是WGS84(EPSG:4326)。如果要使绘图看起来更像在Google Maps中,则必须将其坐标重新投影到许多投影坐标系(单位:米)之一中。您可以使用全球公认的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官方文档

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章