【发布时间】:2020-12-11 16:14:59
【问题描述】:
我想通过颜色编码来表示箭袋的长度(箭头是否称为箭袋?)。这对于 2d 箭袋图没有问题。 Here 完成了。使用 3d 投影,它很难失败。此代码重现了该问题。
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
ax = fig.gca(projection='3d')
# Make the grid
x, y, z = np.meshgrid(np.arange(-0.8, 1, 0.2),
np.arange(-0.8, 1, 0.2),
np.arange(-0.8, 1, 0.8))
# Make the direction data for the arrows
u = np.sin(np.pi * x) * np.cos(np.pi * y) * np.cos(np.pi * z)
v = -np.cos(np.pi * x) * np.sin(np.pi * y) * np.cos(np.pi * z)
w = (np.sqrt(2.0 / 3.0) * np.cos(np.pi * x) * np.cos(np.pi * y) *
np.sin(np.pi * z))
M = np.sqrt(u**2 + v**2 + w**2)
ax.quiver(x, y, z, u, v, w, M)
plt.show()
这会在几个 matplotlib 文件中产生很长的回溯,并以
结尾ValueError: object too deep for desired array
我怎样才能避免这个问题并对我的箭袋进行颜色编码?
【问题讨论】:
-
M应该是什么? -
@venky__ 在数学上是 3d 向量的长度。这里使用相同的方法来实现对箭头进行颜色分级的效果:matplotlib.org/3.1.1/gallery/images_contours_and_fields/…
-
我做到了。我看不出它如何应用于长度问题
-
一直向下滚动,我看到它很有用以及如何完成。 @venky__
标签: python matplotlib 3d