我有一个10x10x10
numpy 矩阵,我试图在 3d 中进行可视化:
from mpl_toolkits.mplot3d import Axes3D
M = np.random.rand(10, 10, 10)
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
counter = range(10)
ax.scatter(counter, counter, counter, c=??)
Run Code Online (Sandbox Code Playgroud)
我想要一个 3d 绘图,其中位置的黑暗i,j,k
由M[i,j,k]
. 我到底应该如何传递M
给scatter()
它才能正确执行此操作?它似乎想要一个二维数组,但我不明白在这种情况下它是如何工作的。
散点需要与颜色数组相同的点数c
。因此,对于 1000 种颜色,您需要 1000 点。
import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
M = np.random.rand(10, 10, 10)
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
counter = range(10)
x,y,z = np.meshgrid(counter, counter, counter)
ax.scatter(x,y,z, c=M.flat)
plt.show()
Run Code Online (Sandbox Code Playgroud)
mau*_*uve -1
尝试:
scatter3D(xs, ys, zs=0, zdir='z', s=20, c=None, depthshade=True, *args, **kwargs)
Run Code Online (Sandbox Code Playgroud)
但 c != 无
https://matplotlib.org/mpl_toolkits/mplot3d/api.html
归档时间: |
|
查看次数: |
3665 次 |
最近记录: |