2016-08-30 7 views
0

でn分ごとに私はPythonの3Dグラフを更新するPythonの

data = # taken from an SQL query in (x, y, z) format # 

x, y, z = zip(*data) 
z = map(float, z) 
grid_x, grid_y = np.mgrid[min(x):max(x):100j, min(y):max(y):100j] 
grid_z = griddata((x, y), z, (grid_x, grid_y), method='cubic') 

fig = plt.figure() 
ax = fig.gca(projection='3d') 
ax.plot_surface(grid_x, grid_y, grid_z, cmap=plt.cm.Spectral) 
plt.show() 

を3Dグラフをプロットするために、次のコードを持って、私はプロットが1分ごとに日付のないようにしたいです。 1分ごとにスレッドを使用してテーブルからデータを取得できますが、プロットを更新できません。

私はお手伝いできますか?

ありがとうございます!

答えて

0

は、私がmatplotlib.animationでこれを行う方法を発見したいくつかの研究の後、この

while True: 
    plt.pause(1) 
    x1,x2,x3=random.uniform(-10,0),random.uniform(0,10),random.uniform(0,0.5) 
    y1,y2,y3=random.uniform(-10,0),random.uniform(0,10),random.uniform(0,0.5) 

    X,Y=np.arange(x1,x2,x3),np.arange(y1,y2,y3) 
    X, Y = np.meshgrid(X, Y) 
    R = np.sqrt(X**2 + Y**2) 
    Z = np.sin(R) 
    surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.coolwarm, 
         linewidth=0, antialiased=False) 

    plt.draw() 

matplotlib.pyplot.pause

Pause for interval seconds. 
If there is an active figure it will be updated and displayed, and the GUI event loop will run during the pause. 
If there is no active figure, or if a non-interactive backend is in use, this executes time.sleep(interval). 
This can be used for crude animation. For more complex animation, see matplotlib.animation. 
This function is experimental; its behavior may be changed or extended in a future release. 
+0

ありがとうございました。私はこれを試して、それが動作するかどうかを見ます。 – user1190937

+0

このソリューションを試してもうまくいきません:(グラフが更新されません。グラフのGUIを閉じると、グラフはその間隔の後に描画されますが、更新されません。 – user1190937

関連する問題