在Cartopy软件包中绘制某个国家/地区的设置范围,Python

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

我正在使用Cartopy for Python软件包。我想在Cartopy软件包的帮助下显示匈牙利的地图。我正在使用以下代码。

import cartopy.crs as ccrs
import cartopy.feature as cfeature
import matplotlib.pyplot as plt


def main():
    fig = plt.figure()
    ax = fig.add_subplot(1, 1, 1, projection=ccrs.PlateCarree())
    ax.set_extent([20, 10, 20, 30], crs=ccrs.PlateCarree())

    ax.add_feature(cfeature.LAND)
    ax.add_feature(cfeature.OCEAN)
    ax.add_feature(cfeature.COASTLINE)
    ax.add_feature(cfeature.BORDERS)
    ax.add_feature(cfeature.LAKES, alpha=1, color="blue")
    ax.add_feature(cfeature.RIVERS)

    plt.show()


if __name__ == "__main__":
    main()

我不了解ax.set_extent([5, 16, 46.5, 56]中的坐标如何工作。这些是德国的坐标,我在网上找到了它们。我查看了德国的经度/纬度,而代码中的这些数字与它们无关。如果有人可以解释这些坐标并给出匈牙利的坐标,我将感到非常高兴。谢谢。

python cartopy cartography
1个回答
0
投票

我知道了。可以使用以下代码创建的图像显示经度/纬度为负/正。 ax.set_extent([x_0, x_1, y_0, y_1]首先定义x并行范围,然后定义y并行范围。

import cartopy.crs as ccrs
import cartopy.feature as cfeature
import matplotlib.pyplot as plt
plt.figure(figsize=(18, 12))
map = plt.axes(projection=ccrs.PlateCarree())
grid_lines = map.gridlines(draw_labels=True)
map.coastlines()
© www.soinside.com 2019 - 2024. All rights reserved.