ale*_*e-6 2 python figure map-projections pandas 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()
Run Code Online (Sandbox Code Playgroud)
region_map这就是正确定义为一块“几何” GeoSeries后的结果。
但是,我无法修改图形的纵横比,甚至无法figsize改变plt.subplots。我是否错过了一些微不足道的事情,或者可能是 geopandas 问题?
谢谢
您的源数据集(region_map)显然是在地理坐标系(单位:纬度和经度)中“编码”的。可以安全地假设您的情况是 WGS84 (EPSG: 4326 )。如果您希望您的绘图看起来更像 Google 地图中的效果,则必须将其坐标重新投影到许多投影坐标系之一(单位:米)。您可以使用全球可接受的 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()
Run Code Online (Sandbox Code Playgroud)
我强烈建议阅读有关管理投影的GeoPandas 官方文档。