【发布时间】:2021-04-20 08:25:50
【问题描述】:
我有 3D 数组形式的数据,每个点都有“强度”。根据强度,我想用更高的 alpha 绘制点。有很多低值异常值,因此颜色编码(带有标量浮点数)将不起作用,因为它们会使真实数据黯然失色。
我尝试过的:
#this generates a 3D array with higher values around the center
a = np.array([0,1,2,3,4,5,4,3,2,1])
aa = np.outer(a,a)
aaa = np.einsum("ij,jk,jl",aa,aa,aa)
x_,y_,z_,v_ = [],[],[],[]
from matplotlib.colors import to_rgb,to_rgba
for x in range(aaa.shape[0]):
for y in range(aaa.shape[1]):
for z in range(aaa.shape[2]):
x_.append(x)
y_.append(y)
z_.append(z)
v_.append(aaa[x,y,z])
r,g,b = to_rgb("blue")
color = np.array([[r,g,b,a] for a in v_])
fig = plt.figure()
ax = fig.add_subplot(projection = '3d')
ax.scatter(x_,y_,z_,c =color)
plt.show()
散点图文档说颜色可以是 RGBA 的 2D 数组,我确实通过了。但是,当我尝试运行代码时,出现以下错误:
ValueError: 'c' 参数有 4000 个元素,与大小为 1000 的 'x' 和 'y' 不一致。
【问题讨论】:
标签: python matplotlib