matplotlib.mplot3d 立方体表面的底图
正如标题所示,我试图在 matplotlib.mplot3d 线图的 z=0 表面上绘制底图地图。我知道 Axes3D 对象能够在 z=0 表面上绘图(通过 Axes3D.plot、Axes3D.scatter 等),但我不知道如何使用 Basemap 对象来执行此操作。希望下面的代码足够清楚地展示了我需要的内容。任何想法将不胜感激!
import matplotlib.pyplot as pp
from mpl_toolkits.mplot3d import Axes3D
from mpl_toolkits.basemap import Basemap
# make sample data for 3D lineplot
z = np.linspace(-2, 2, 100)
r = z**2 + 1
x = r * np.sin(theta)
y = r * np.cos(theta)
# make the 3D line plot
FIG = ct.pp.figure()
AX = Axes3D(FIG)
AX.plot(x, y, z, '-b')
# make the 2D basemap
### NEEDS TO SOMEHOW BE AT z=0 IN FIG
M = ct.Basemap(projection='stere', width=3700e3, height=2440e3,
lon_0=-5.0, lat_0=71.0, lat_ts=71.0,
area_thresh=100, resolution='c')
PATCHES = M.fillcontinents(lake_color='#888888', color='#282828')
As the title suggests, I'm trying to plot a Basemap map on the z=0 surface of a matplotlib.mplot3d lineplot. I know the Axes3D object is capable of plotting on the z=0 surface (via Axes3D.plot, Axes3D.scatter, etc.), but I can't figure out how to do so with a Basemap object. Hopefully the code below shows what I need clearly enough. Any ideas would be much appreciated!
import matplotlib.pyplot as pp
from mpl_toolkits.mplot3d import Axes3D
from mpl_toolkits.basemap import Basemap
# make sample data for 3D lineplot
z = np.linspace(-2, 2, 100)
r = z**2 + 1
x = r * np.sin(theta)
y = r * np.cos(theta)
# make the 3D line plot
FIG = ct.pp.figure()
AX = Axes3D(FIG)
AX.plot(x, y, z, '-b')
# make the 2D basemap
### NEEDS TO SOMEHOW BE AT z=0 IN FIG
M = ct.Basemap(projection='stere', width=3700e3, height=2440e3,
lon_0=-5.0, lat_0=71.0, lat_ts=71.0,
area_thresh=100, resolution='c')
PATCHES = M.fillcontinents(lake_color='#888888', color='#282828')
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只需将地图作为 3d 集合添加到 Axes3D 实例即可:
Just add your map as a 3d collection to the Axes3D instance:
AX.add_collection3d(M.drawcoastlines())
有效,但
PATCHES = M.fillContinents(lake_color='#888888', color='#282828')
无效。
添加颜色填充后,您会收到类似以下内容的错误:“AttributeError:‘Polygon’对象没有属性‘do_3d_projection’”
返回多边形数组,而不是 add_collection() 所需的输入之一。
collect.PatchCollection()
似乎也不起作用。那么你用什么来将 `M.fillContinents(lake_color='#888888', color='#282828') 添加到 3D 绘图中呢?
AX.add_collection3d(M.drawcoastlines())
works but
PATCHES = M.fillcontinents(lake_color='#888888', color='#282828')
does not work.
As soon as you add color fill you get an error similar to: "AttributeError: 'Polygon' object has no attribute 'do_3d_projection'"
returns an array of Polygons, not one of the inputs required by add_collection().
collect.PatchCollection()
does not seem to work either.So what do you use to add `M.fillcontinents(lake_color='#888888', color='#282828') to a 3D plot?