2
我試圖使用matplotlib的散點圖功能(Python 2.7版,Spyder的GUI)來繪製這個簡單的點的集合:點錯在與matplotlib散點圖函數z座標
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的問題?