利用地图学绘制地球二进制地图。

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

我想用cartopy来绘制一张只有两种颜色的地球地图。例如,陆地,填充在白色和海洋的黑暗。现在,我使用海岸线()方法,创建大陆的轮廓,但我不知道如何填补他们的颜色,或填补海洋与之一。

 import matplotlib.pyplot as plt

 fig = plt.figure(figsize=(12,6))
 ax = fig.add_subplot(1,1,1,projection = ccrs.EckertIV())
 ax.clear()
 cs = ax.contourf(longitude,lattitude,A,transform=ccrs.PlateCarree(),
    cmap='gist_gray',alpha=0.3)#,extend = 'both')
 ax.coastlines(color = 'black')

它产生的地图与大陆,但它是所有的白色,除了黑色的海岸线。

先谢谢你 !

PS : 这是我的第一篇帖子,所以如果你需要更精确地解决我的问题,或者如果我需要以某种方式编辑我的帖子,请告诉我。

python dictionary matplotlib cartopy
1个回答
1
投票

这是一个最小的例子。在你的例子中,你没有显示什么是你的 longitude, latitudeA 数据,所以我只是用一条简单的线代替。

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

latitude = [0, 10]
longitude = [0, 20]

fig = plt.figure(figsize=(12, 6))
ax = fig.add_subplot(1, 1, 1, projection=ccrs.EckertIV())

ax.set_global()
# set_extent([-180, 180, -90, 90], crs=ccrs.PlateCarree())

ax.patch.set_facecolor(color='black')
# or
# ax.background_patch.set_facecolor(color='black')   # cartopy < v0.18
# or
# ax.add_feature(cartopy.feature.OCEAN, color='black')

ax.add_feature(cartopy.feature.LAND, color='white')

ax.plot(longitude, latitude, color='red', transform=ccrs.PlateCarree())

您使用的是 EckertIV 投影,所以您必须告知轴,您的经度和纬度值是指向一个 PlateCarree 投影。这就是为什么你必须使用 crs 千瓦 set_extent (如果不使用 set_global)和 transform 千瓦 plot.

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.