2017-01-10 6 views
0

私はシミュレーションのために多くのデータを持っています。私はそれを3Dプロットで表現したいと思います。私は10秒を表す10ポイントを持っていると言うことができます。毎秒私は〜数百万のエネルギー値を持つリストを持っています(リストの長さは毎秒一定です)。 3次元の点の分布が(1,2,3,4 ...のように)一定でなければならないサーフェスとしてプロットしたいと思います。1つの定数分布を持つmatplotlibで3Dグラフをプロットする

サーフェスのチュートリアルについては読んでいますが、サンプルリストは理解できない方法で入れ子になっています。私がこれまで試したどのような

import matplotlib.pyplot as plt 
from mpl_toolkits.mplot3d import axes3d 
fig = plt.figure() 
ax = fig.add_subplot(111, projection='3d') 
X, Y, Z = axes3d.get_test_data(0.05) 
print(X) 
ax.plot_wireframe([1,2,3,4,2,4,6,8], [1,2,3,4,1,2,3,4], [1,1,1,1,2,2,2,2]) 
plt.show() 

は、ここで私は、最初の数秒でエネルギーが1,2,3,4であり、第二秒間、彼らは2,4,6,8であることを前提としています。私は手動で第3軸のための分布を追加しようとしました(したがって、2つのポイントの1,2,3,4,1,2,3,4)。

上記のコードは出力を生成しません。

これは何とかできますか?

+0

あなたのコードを実行すると、現在[Python 2.7.12 | Anaconda custom(64-bit) 'を実行している[この画像](https://i.stack.imgur.com/JbGcR.png)が表示されます。 'matplotlib .__ version__ >>> '1.4.3''。 [チュートリアル](http://matplotlib.org/mpl_toolkits/mplot3d/tutorial.html#mpl_toolkits.mplot3d.Axes3D.plot_wireframe)を見たことがありますか?最初の配列はx値、2番目の配列はy値、3番目はz値なので、メッシュ上の点は '(X [i]、Y [i]、Z [i])'になります。任意の近隣(2つのインデックス「i」および第3の「i + 1」または「i-1」を有するポイント)に接続されてもよい。 – berna1111

答えて

2

出力が全く得られないというのは奇妙です。新しいウィンドウは開きませんか? matplotlibをより簡単にexampleに使用できますか?

私は、Python 2.7.2を使用して、私のコメントで述べたようにして1.4.3をmatplotlibの私が取得: Given example output.

私が試してみて、あなたが何をしたいのかをエミュレート、それは便利です場合を見てみましょうするようにコードを変更:

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

N_Times = 10 
N_energies = 50 # per time 
Times = np.arange(N_Times) # array with all the times 
Energies_indexes = np.arange(N_energies) # array with the energy indexes 
X, Y = np.meshgrid(Times, Energies_indexes) # generates the base grid 
Energies = np.asarray([Energies_indexes + t for t in Times]) 
# The above array should have one line of energies for each 
# value of time. So Energies[0] would be the list of energies 
# for the first time value, and Energies[0][0] the first energy 
# for that time. 
# This is simpler to understand, I think, but will mean we'll have 
# to transpose it (.T) to make it compatible with meshgrid*. 
# Adapt accordingly. 
# * see: http://stackoverflow.com/questions/27495462/ 

print X.shape, Y.shape, Energies.shape 
print "... and that's why we use the trasnpose (.T) when ploting" 

fig = plt.figure() 
ax = fig.add_subplot(111, projection='3d') 
ax.plot_wireframe(X, Y, Energies.T) 
ax.set_xlabel('Time (?)') 
ax.set_ylabel('Energies Index (#)') 
ax.set_zlabel('Energy Value (?)') 
plt.show() 

:予想通り、そのインデックスに沿って、時間とともに増加するエネルギーで New example output.

+0

ありがとう、すべてを説明し、完璧な答え! –

関連する問題