【问题标题】:fill oceans for basemap in 3D为 3D 底图填充海洋
【发布时间】:2019-02-22 15:02:46
【问题描述】:

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

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

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

【问题讨论】:

  • 欢迎来到stackoverflow。对我的回答有任何反馈吗?

标签: matplotlib-basemap


【解决方案1】:

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

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()

结果图:

【讨论】:

    猜你喜欢
    • 2018-07-15
    • 2020-05-08
    • 2022-09-26
    • 1970-01-01
    • 2017-01-11
    • 1970-01-01
    • 2021-05-14
    • 2016-04-02
    • 1970-01-01
    相关资源
    最近更新 更多