使用 add_collection3d 绘制 Poly3DCollection [英] Plotting Poly3DCollection using add_collection3d

查看:24
本文介绍了使用 add_collection3d 绘制 Poly3DCollection的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有表示空间中点的球坐标的相同大小的树数组.我想绘制它们在笛卡尔坐标中的变换.我正在尝试生成一个表面,并且由于我的数组的维度,我需要使用 add_collection3d 方法而不是 plot_surface 方法.原始数组在球坐标中具有不同的长度,并且向笛卡尔坐标的转换不是线性的.

I have tree arrays of the same size representing the spherical coordinates of points in space. I want to plot them transformed in cartesian coordinates. I am trying to produce a surface and I need to use the add_collection3d method instead of the plot_surface because of the dimensions of my arrays. The original arrays have different lengths in spherical coordinates and the transformation into cartesian is not linear.

一个简单的例子如下:

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 和一个 LightSource(不影响绘图),以及一个 antialiased 因为在我的真实数据 z 是一个包含 20000 个元素的数组.

I would like to apply a cmap and a LightSource (don't affect the plot), as well as an antialiased because in my real data z is an array with 20000 elements.

期待听到您的集体智慧!

Looking forward to hearing from your collective intelligence!

推荐答案

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

Solution: reshape all the three vectors and use surface plot!

从三个一维数组创建一个 3D 曲面图

这篇关于使用 add_collection3d 绘制 Poly3DCollection的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆