为3D底图填充海洋

时间:2019-02-22 15:02:47

标签: matplotlib-basemap

我想用3D填充底图,但是

ax.add_collection3d(m.drawmapboundary(fill_color='aqua'))

似乎不起作用,因为底图的drawmapboundary方法没有返回add_collection3d支持的对象,而是返回了 matplotlib.collections.PatchCollection 对象。是否有任何其他解决方法与针对陆地多边形here的解决方法类似?谢谢!

1 个答案:

答案 0 :(得分:0)

在地图下方绘制一个矩形(多边形)是一种解决方案。这是您可以尝试的工作代码。

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from mpl_toolkits.basemap import Basemap
from matplotlib.collections import PolyCollection

map = Basemap()
fig = plt.figure()
ax = Axes3D(fig)

ax.azim = 270
ax.elev = 50
ax.dist = 8

ax.add_collection3d(map.drawcoastlines(linewidth=0.20))
ax.add_collection3d(map.drawcountries(linewidth=0.15))

polys = []
for polygon in map.landpolygons:
    polys.append(polygon.get_coords())

# This fills polygons with colors
lc = PolyCollection(polys, edgecolor='black', linewidth=0.3, \
                    facecolor='#BBAAAA', alpha=1.0, closed=False)
lcs = ax.add_collection3d(lc, zs=0)  # set zero zs

# Create underlying blue color rectangle
# It's `zs` value is -0.003, so it is plotted below land polygons
bpgon = np.array([[-180., -90],
       [-180, 90],
       [180, 90],
       [180, -90]])
polys2 = []
polys2.append(bpgon)
lc2 = PolyCollection(polys2, edgecolor='none', linewidth=0.1, \
                    facecolor='#445599', alpha=1.0, closed=False)
lcs2 = ax.add_collection3d(lc2, zs=-0.003)  # set negative zs value

plt.show()

结果图:

enter image description here