从Matplotlib文档页面的example中借用并稍微修改代码
import numpy as np
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()
ax = fig.add_subplot(111, projection='3d')
n = 100
for c, m, zl, zh in [('r', 'o', -50, -25), ('b', '^', -30, -5)]:
xs = randrange(n, 23, 32)
ys = randrange(n, 0, 100)
zs = randrange(n, zl, zh)
cs = randrange(n, 0, 100)
ax.scatter(xs, ys, zs, c=cs, marker=m)
ax.set_xlabel('X Label')
ax.set_ylabel('Y Label')
ax.set_zlabel('Z Label')
plt.show()
将为每个点提供具有不同颜色的三维散点图(本例中为随机颜色)。向图中添加颜色条的正确方法是什么,因为添加plt.colorbar()
或ax.colorbar()
似乎不起作用。
这会产生一个颜色条(尽管可能不是您需要的颜色条):
替换此行:
与
然后使用
接近尾声
相关问题 更多 >
编程相关推荐