python 3d绘图 拖动_使用python-matplotlib连续3D绘图(即图形更新)?
我有一個(gè)模擬計(jì)算每次模擬迭代的表面數(shù)據(jù).
我想連續(xù)將該數(shù)據(jù)繪制為同一窗口的表面圖(在每次迭代中更新圖),以便了解它是如何演變的并檢查算法.
我的想法是創(chuàng)建一個(gè)類來初始化窗口/繪圖,然后從模擬循環(huán)內(nèi)部重繪到該窗口.這是我提出的課程:
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
from matplotlib.ticker import LinearLocator, FixedLocator, FormatStrFormatter
import matplotlib
matplotlib.interactive( False )
class plot3dClass( object ):
def __init__( self, systemSideLength, lowerCutoffLength ):
self.systemSideLength = systemSideLength
self.lowerCutoffLength = lowerCutoffLength
self.fig = plt.figure()
self.ax = self.fig.add_subplot( 111, projection='3d' )
self.ax.set_zlim3d( -10e-9, 10e9 )
X = np.arange( 0, self.systemSideLength, self.lowerCutoffLength )
Y = X
self.X, self.Y = np.meshgrid(X, Y)
self.ax.w_zaxis.set_major_locator( LinearLocator( 10 ) )
self.ax.w_zaxis.set_major_formatter( FormatStrFormatter( '%.03f' ) )
heightR = np.zeros( self.X.shape )
self.surf = self.ax.plot_surface( self.X, self.Y, heightR, rstride=1, cstride=1, cmap=cm.jet, linewidth=0, antialiased=False )
#~ self.fig.colorbar( self.surf, shrink=0.5, aspect=5 )
plt.show()
def drawNow( self, heightR ):
self.surf = self.ax.plot_surface( self.X, self.Y, heightR, rstride=1, cstride=1, cmap=cm.jet, linewidth=0, antialiased=False )
plt.draw() # redraw the canvas
time.sleep(1)
我對(duì)這段代碼的問題是代碼在’plt.show()’停止,并且只在我關(guān)閉繪圖窗口時(shí)繼續(xù).另外我不確定’self.ax.plot_surface(…)’和’plt.draw()’的調(diào)用是否會(huì)像我希望的那樣更新數(shù)字.
這個(gè)班級(jí)是正確的方向嗎?
如果是:需要進(jìn)行哪些修改?
如果沒有:有人可以給我建議如何實(shí)現(xiàn)我想要的?
我意識(shí)到這個(gè)問題對(duì)其他人來說可能看起來微不足道,但我(老實(shí)說)確實(shí)昨天花了整整一天時(shí)間在谷歌上嘗試并且我不知所措……
非常感謝任何幫助,以便我可以回到我的實(shí)際工作.
坦克很多提前.
作為參考:
我還發(fā)現(xiàn)了以下代碼,它可以做什么,我想要什么,但是它是2D的,所以它對(duì)我沒有幫助:
from pylab import *
import time
ion()
tstart = time.time() # for profiling
x = arange(0,2*pi,0.01) # x-array
line, = plot(x,sin(x))
for i in arange(1,200):
line.set_ydata(sin(x+i/10.0)) # update the data
draw() # redraw the canvas
print 'FPS:' , 200/(time.time()-tstart)
總結(jié)
以上是生活随笔為你收集整理的python 3d绘图 拖动_使用python-matplotlib连续3D绘图(即图形更新)?的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 一个具有20位地址和32位字长的存储器_
- 下一篇: 搜狗高速浏览器提示您 怎么关闭_那些浏览