我试图使用matplotlib的散点图函数(Python 2.7,Spyder GUI)绘制这个简单的点集:
X=[0 0 1 1]
Y=[0 1 0 1]
Z=[0 1 1 1]
这实际上代表OR运算符,所以我想为z = 0的点设置不同的标记/颜色。这是我的代码:
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
X = np.zeros( (4,1) )
X[0,0] = 0
X[1,0] = 0
X[2,0] = 1
X[3,0] = 1
Y = np.zeros( (4,1) )
Y[0,0] = 0
Y[1,0] = 1
Y[2,0] = 0
Y[3,0] = 1
Z = np.zeros( (4,1) )
Z[0,0] = 0
Z[1,0] = 1
Z[2,0] = 1
Z[3,0] = 1
for i in range(0,len(Z)):
if Z[i]:
ax.scatter(X[i],Y[i],Z[i],'x',color="r")
else:
ax.scatter(X[i],Y[i],Z[i],'o',color="b")
ax.view_init(elev=0., azim=200)
ax.set_xlabel('X Label')
ax.set_ylabel('Y Label')
ax.set_zlabel('Z Label')
这是我得到的情节:
显然,底部中间的红点应位于情节的左上角。
我的代码是否有问题,或者是matplotlib的问题?