matplotlib-basemap - 为 3D 底图填充海洋
问题描述
我想为我的 3D 底图填充海洋,但是
ax.add_collection3d(m.drawmapboundary(fill_color='aqua'))
似乎不起作用,因为底图 drawmapboundary 方法不返回 add_collection3d 支持的对象,而是matplotlib.collections.PatchCollection对象。有没有类似于这里为陆地多边形所做的解决方法?谢谢!
解决方案
在地图下方绘制一个矩形(多边形)是一种解决方案。这是您可以尝试的工作代码。
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()
结果图:
推荐阅读
- java - 从生成的缓存键中删除缓存名称
- python - 你能让图像在 tkinter 中显示为按钮而不是按钮吗?
- c# - 带有 WPF 附加属性的 PropertyChangedCallback 与 CoerceValueCallback
- dart - 如果请求的图像不在我的资产中,有没有办法显示图像?
- java - 休眠日期,时间戳类型令人困惑
- reactjs - React Native: Having different states per dynamic view
- ansible - 带有 become 和 chdir 的 Ansible 命令
- r - 使用 R 和 Rvest 自动完成并发送表单
- elixir - Ecto:对虚拟字段进行计数查询的动态 order_by
- selenium - 如何将 Python 对象从 Julia 传递给 Python 方法?