三维散点图与matplotlib
问题描述:
我使用分散3D图中matplotlib在python对于绘制下列数据的颜色,三维散点图与matplotlib
x y z b2
3.28912855713 4.64604863545 3.95526335139 1.0
3.31252670518 4.65385917898 3.96834118896 1.0
当情节为2d,
fig = plt.figure()
ax = fig.add_subplot(111)
line =ax.scatter(x,y,c=b2,s=500,marker='*',edgecolors='none')
cb = plt.colorbar(line)
,我想绘制3D点,该代码是:
fig = plt.figure()
ax = fig.add_subplot(111,projection='3d')
line = ax.scatter(x,y,z,c=b2,s=1500,marker='*',edgecolors='none',depthshade=0)
cb = plt.colorbar(line)
我也得到下面的图形,这是不正确的,因为颜色应该是绿色的像前一种情况(B2没有按不会改变)。
我错过了什么吗?
答
可能不是。我不知道你使用的是什么版本的Matplotlib,但是在某些时候这个问题存在一个错误,这个错误显然仍然影响我今天使用的版本,即1.5.1(关于这个,请查看this question)。
针对您的问题调整@Yann解决方案应该可以解决该问题。我在我的电脑测试了它,结果是:在进入小区的
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
x = [3.28912855713, 3.31252670518]
y = [4.64604863545, 4.65385917898]
z = [3.95526335139, 3.96834118896]
b2 = [1, 1]
fig = plt.figure()
ax = fig.add_subplot(111,projection='3d')
line = ax.scatter(x, y ,z , c=b2, s=1500, marker='*', edgecolors='none', depthshade=0)
cb = plt.colorbar(line)
def forceUpdate(event):
global line
line.changed()
fig.canvas.mpl_connect('draw_event', forceUpdate)
plt.show()
图像和旋转后是:
它曾与1.4。 3也。谢谢。 –