Python Data Science 简明教程

Python - Geographical Data

现在,很多开源 Python 库已被创建出来,用以表示地理地图。它们具有高度的可定制性,并提供各种各样的地图,描绘了不同形状和颜色的区域。Cartopy 就是这样一种包。你可以在 Cartopy 从本地环境中下载并安装此包。你可以在其库中找到大量示例。

Many open source python libraries now have been created to represent the geographical maps. They are highly customizable and offer a varierty of maps depicting areas in different shapes and colours. One such package is Cartopy. You can download and install this package in your local environment from Cartopy. You can find numerous examples in its gallery.

在以下示例中,我们展示了一部分世界地图,其中显示了亚洲和澳大利亚的部分地区。你可以调整方法 set_extent 中参数的值,以定位世界地图的不同区域。

In the below example we show a portion of the world map showing parts of Asia and Australia. You can adjust the values of the parameters in the method set_extent to locate different areas of world map.

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

fig = plt.figure(figsize=(15, 10))
ax = fig.add_subplot(1, 1, 1, projection=ccrs.PlateCarree())

    # make the map global rather than have it zoom in to
    # the extents of any plotted data

ax.set_extent((60, 150, 55, -25))

ax.stock_img()
ax.coastlines()

ax.tissot(facecolor='purple', alpha=0.8)

plt.show()

它的 output 如下所示 −

Its output is as follows −

geographic