在3D中填充底图以显示底图

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

我想在3D中为海底填充海洋,但是

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

似乎没有用,因为底图drawmapboundary方法不返回add_collection3d支持的对象,而是返回matplotlib.collections.PatchCollection对象。有没有类似于陆地多边形here的解决方法?谢谢!

matplotlib-basemap
1个回答
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

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