是的,是這樣的:
更新這是一個帶彩條的一個版本。
import numpy as np
from pylab import *
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
def randrange(n, vmin, vmax):
return (vmax-vmin)*np.random.rand(n) + vmin
fig = plt.figure(figsize=(8,6))
ax = fig.add_subplot(111,projection='3d')
n = 100
xs = randrange(n, 23, 32)
ys = randrange(n, 0, 100)
zs = randrange(n, 0, 100)
colmap = cm.ScalarMappable(cmap=cm.hsv)
colmap.set_array(zs)
yg = ax.scatter(xs, ys, zs, c=cm.hsv(zs/max(zs)), marker='o')
cb = fig.colorbar(colmap)
ax.set_xlabel('X Label')
ax.set_ylabel('Y Label')
ax.set_zlabel('Z Label')
plt.show()
的樣子:
更新下面是一些4維屬性着色數據點的一個明顯的例子。
import numpy as np
from pylab import *
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
def randrange(n, vmin, vmax):
return (vmax-vmin)*np.random.rand(n) + vmin
fig = plt.figure(figsize=(8,6))
ax = fig.add_subplot(111,projection='3d')
n = 100
xs = randrange(n, 0, 100)
ys = randrange(n, 0, 100)
zs = randrange(n, 0, 100)
the_fourth_dimension = randrange(n,0,100)
colors = cm.hsv(the_fourth_dimension/max(the_fourth_dimension))
colmap = cm.ScalarMappable(cmap=cm.hsv)
colmap.set_array(the_fourth_dimension)
yg = ax.scatter(xs, ys, zs, c=colors, marker='o')
cb = fig.colorbar(colmap)
ax.set_xlabel('X Label')
ax.set_ylabel('Y Label')
ax.set_zlabel('Z Label')
plt.show()
真棒,非常感謝!你知道我怎麼能想象什麼顏色代表熱圖中的哪個值? – user1048858
更新了我的答案! – seth
嗨,我用一個明確的例子更新了我的答案,用任何你想要的值向量來着色你的數據。如果您發現我的答案有用,請將其標記爲答案? – seth