lam*_*bda 4 plot matplotlib python-2.7
我对matplotlib很新(这也是我的第一个问题).我试图表示脑电图记录的头皮表面电位.到目前为止,我有一个球体投影的二维图形,我使用contourf生成,几乎归结为普通的热图.
有没有什么方法可以在半个球体上完成?,即生成具有由值列表给出的表面颜色的3D球体?像这样的东西,http://embal.gforge.inria.fr/img/inverse.jpg,但是我只有半个球体就足够了.
我已经看到了一些相关的问题(例如,Matplotlib 3d彩色图 - 是否可能?),但它们要么没有真正解决我的问题,要么到目前为止仍然没有答案.
我也花了一个上午看了无数的例子.在我发现的大部分内容中,表面某个特定点的颜色表示其Z值,但我不希望...我想绘制表面,然后用数据指定颜色I有.
您可以使用plot_trisurf并通过方法将自定义字段分配给基础ScalarMappableset_array.
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import matplotlib.tri as mtri
(n, m) = (250, 250)
# Meshing a unit sphere according to n, m
theta = np.linspace(0, 2 * np.pi, num=n, endpoint=False)
phi = np.linspace(np.pi * (-0.5 + 1./(m+1)), np.pi*0.5, num=m, endpoint=False)
theta, phi = np.meshgrid(theta, phi)
theta, phi = theta.ravel(), phi.ravel()
theta = np.append(theta, [0.]) # Adding the north pole...
phi = np.append(phi, [np.pi*0.5])
mesh_x, mesh_y = ((np.pi*0.5 - phi)*np.cos(theta), (np.pi*0.5 - phi)*np.sin(theta))
triangles = mtri.Triangulation(mesh_x, mesh_y).triangles
x, y, z = np.cos(phi)*np.cos(theta), np.cos(phi)*np.sin(theta), np.sin(phi)
# Defining a custom color scalar field
vals = np.sin(6*phi) * np.sin(3*theta)
colors = np.mean(vals[triangles], axis=1)
# Plotting
fig = plt.figure()
ax = fig.gca(projection='3d')
cmap = plt.get_cmap('Blues')
triang = mtri.Triangulation(x, y, triangles)
collec = ax.plot_trisurf(triang, z, cmap=cmap, shade=False, linewidth=0.)
collec.set_array(colors)
collec.autoscale()
plt.show()
Run Code Online (Sandbox Code Playgroud)

| 归档时间: |
|
| 查看次数: |
2645 次 |
| 最近记录: |