Matplotlib 使用add_collection3d打印Poly3DCollection

Matplotlib 使用add_collection3d打印Poly3DCollection,matplotlib,3d,light,Matplotlib,3d,Light,我有同样大小的树数组,表示空间中点的球坐标。我想画出笛卡尔坐标系下的变换图。我正在尝试生成曲面,由于阵列的尺寸,我需要使用add\u collection3d方法而不是plot\u surface。原始阵列在球坐标系中具有不同的长度,并且到笛卡尔坐标系的转换不是线性的 下面是一个简化的示例: import numpy as np import matplotlib.pyplot as plt from matplotlib.colors import LightSource from mpl_t

我有同样大小的树数组,表示空间中点的球坐标。我想画出笛卡尔坐标系下的变换图。我正在尝试生成曲面,由于阵列的尺寸,我需要使用
add\u collection3d
方法而不是
plot\u surface
。原始阵列在球坐标系中具有不同的长度,并且到笛卡尔坐标系的转换不是线性的

下面是一个简化的示例:

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.colors import LightSource
from mpl_toolkits.mplot3d.art3d import Poly3DCollection
from mpl_toolkits.mplot3d import Axes3D


phi_rad = np.linspace(0,360, 10)/180.0*np.pi
theta_rad = np.linspace(0,360, 10)/180.0*np.pi # cos(theta)
counts_str = np.linspace(0, 100, 10) # counts

# convertion to cartesian coordinates 1D arrays
x = counts_str * np.sin(theta_rad) * np.cos(phi_rad)
y = counts_str * np.sin(theta_rad) * np.sin(phi_rad)
z_str = counts_str * np.cos(theta_rad)

verts = [list(zip(x, y, z_str))]

fig = plt.figure()
ax = Axes3D(fig)

ax.add_collection3d(Poly3DCollection(verts, cmap="hot", alpha=0.9))
ls = LightSource(azdeg=225.0, altdeg=45.0)

ax.set_xlim3d(x.min(), x.max())
ax.set_ylim3d(y.min(), y.max())
ax.set_zlim3d(z_str.min(), z_str.max())

plt.show()
我想应用
cmap
光源(不影响绘图),以及
抗锯齿
,因为在我的真实数据中,z是一个包含20000个元素的数组


期待您的集体智慧

解决方案:重塑所有三个向量并使用曲面打印