我想通过颜色编码来指示箭袋的长度(箭头称为箭袋吗?)。对于二维箭袋图来说这不是问题。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
我怎样才能避免这个问题并对我的箭袋进行颜色编码?