微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用add_collection3d绘制Poly3DCollection

如何解决使用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,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()

我想应用cmapLightSource(不影响绘图),以及antialiased,因为在我的真实数据中z是一个具有20000的数组元素。

期待您的集体智慧!

解决方法

解决方案:重塑所有三个向量并使用表面图!

Creating a 3D surface plot from three 1D arrays

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。