matplotlib.mplot3d多维数据集正面的底图

时间:2011-05-28 03:15:58

标签: python plot matplotlib matplotlib-basemap

正如标题所示,我正在尝试在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')

2 个答案:

答案 0 :(得分:1)

只需将地图作为3d集合添加到Axes3D实例:

import numpy as np
import matplotlib.pyplot as pp
from mpl_toolkits.mplot3d import Axes3D
from mpl_toolkits.basemap import Basemap

theta = np.linspace(-4 * np.pi, 4 * np.pi, 100)
z = np.linspace(-500, 500, 100)
r = z**2 + 1
x = r * np.sin(theta)
y = r * np.cos(theta)

FIG = pp.figure()
AX = Axes3D(FIG)
AX.plot(x, y, z, '-b')

M = Basemap(projection='stere', width=3700e3, height=2440e3,
               lon_0=-5.0, lat_0=71.0, lat_ts=71.0,
               area_thresh=100, resolution='c')
AX.add_collection3d(M.drawcoastlines())
AX.grid(True)

pp.draw()
pp.show()

答案 1 :(得分:-2)

AX.add_collection3d(M.drawcoastlines())

有效但

PATCHES = M.fillcontinents(lake_color='#888888', color='#282828')

不起作用。

只要添加颜色填充,就会出现类似于以下内容的错误:“AttributeError:'Polygon'对象没有属性'do_3d_projection'”

M.fillcontinents(lake_color='#888888', color='#282828')`

返回多边形数组,而不是add_collection()所需的输入之一。 collect.PatchCollection()似乎也无效。

那你用什么来添加`M.fillcontinents(lake_color ='#888888',color ='#282828')到3D情节?