matplotlib - 使用 add_collection3d 绘制 Poly3DCollection
问题描述
我有相同大小的树数组,表示空间中点的球坐标。我想将它们绘制成笛卡尔坐标。我正在尝试生成一个表面,我需要使用该add_collection3d
方法而不是plot_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()
我想应用 acmap
和 a LightSource
(不影响绘图),以及 aantialiased
因为在我的真实数据中 z 是一个包含 20000 个元素的数组。
期待听到您的集体智慧!
解决方案
解决方案:重塑所有三个向量并使用曲面图!
推荐阅读
- ruby-on-rails - 获取控制器操作中使用的路径段列表
- amazon-web-services - AWS Cognito 和 AWS S3 集成?
- javascript - 为什么javascript类和函数具有等于'Function'的构造函数属性?
- python - 计算 dask 数据框中 2 个日期时间列之间的天数
- jobs - 用软件执行作业勺
- qt - Qt3D点线拾取?
- node.js - NodeJS / MongoDB - 避免 mongoose 错误地节省当前时间
- r - 在数据框中生成具有条件值的行
- javascript - 如何检查消息是否成功保存到本地 Redis?
- javascript - 是否有任何解决方案可以删除对 Element.querySelector 和其他 dom 访问方法的访问?