2016-07-12 4 views
-1

を平準こんにちは私は、単純な座標で3D表現を作成するように見えることはできません - 私はラインを望んでいない - (0異なる各coordsのがタッチスクリーンに適用され、指を表す)matplotlibの部3d - 初心者が

from mpl_toolkits.mplot3d import axes3d 
import matplotlib.pyplot as plt 
import numpy as np 

fig = plt.figure() 
ax = fig.add_subplot(111, projection='3d') 

X =[1,2,3,4,5,6,7,8,9,10] 
Y =[5,6,2,3,13,4,1,2,4,8] 
Z =[0,2,0,5,0,0,0,0,8,0] 
ax.set_xlabel('X Label') 
ax.set_ylabel('Y Label') 
ax.set_zlabel('Z Label') 

ax.plot_surface(X, Y, Z, rstride=10, cstride=10) 

plt.show() 
+0

を取得します。これは、生産しますあなたが望むものとあなたの問題が何であるかを理解してはいけません。どうか明らかにしてください。 – Julien

+1

'X、Y、Z'は2次元配列ですか? [このリンク](http://matplotlib.org/mpl_toolkits/mplot3d/tutorial.html)をチェックし、 'plot_surface'の例を見てください。 – ThePredator

+1

3D散布図がほしいと思うようですね。 – DavidG

答えて

1

plot_surfaceを実行するには、入力配列(X,Y,Z)が2次元配列である必要があります。 あなたの場合、1D配列でフィードをしようとしているので、 コードを実行すると、グリッドだけで空のプロットが得られます。ここで

は動作しますあなたのコードの例です:

ここ
from mpl_toolkits.mplot3d import axes3d 
import matplotlib.pyplot as plt 
import numpy as np 

fig = plt.figure() 
ax = fig.add_subplot(111, projection='3d') 

X =[1,2,3,4,5,6,7,8,9,10] 
Y =[5,6,2,3,13,4,1,2,4,8] 
Z =[0,2,0,5,0,0,0,0,8,0] 

x_plot,y_plot = np.meshgrid(X,Y) 
z_plot = x_plot**2 + x_plot**2 

ax.set_xlabel('X Label') 
ax.set_ylabel('Y Label') 
ax.set_zlabel('Z Label') 

ax.plot_surface(x_plot,y_plot,z_plot) 

plt.show() 

あなたが見ることができるように、私は入力2次元配列として与えています。私はnumpy.meshgridを使って作った。 Z軸は任意の値である。

enter image description here

をOR他の人が示唆されているとして、あなただけの3D散布図が、その場合には、単に

ax.scatter(X,Y,Z) 

を使用したいとあなたは

enter image description here