失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > python 3d绘图 拖动_使用python-matplotlib连续3D绘图(即图形更新)?

python 3d绘图 拖动_使用python-matplotlib连续3D绘图(即图形更新)?

时间:2024-05-25 22:50:54

相关推荐

python 3d绘图 拖动_使用python-matplotlib连续3D绘图(即图形更新)?

我有一个模拟计算每次模拟迭代的表面数据.

我想连续将该数据绘制为同一窗口的表面图(在每次迭代中更新图),以便了解它是如何演变的并检查算法.

我的想法是创建一个类来初始化窗口/绘图,然后从模拟循环内部重绘到该窗口.这是我提出的课程:

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)

我对这段代码的问题是代码在’plt.show()’停止,并且只在我关闭绘图窗口时继续.另外我不确定’self.ax.plot_surface(…)’和’plt.draw()’的调用是否会像我希望的那样更新数字.

这个班级是正确的方向吗?

如果是:需要进行哪些修改?

如果没有:有人可以给我建议如何实现我想要的?

我意识到这个问题对其他人来说可能看起来微不足道,但我(老实说)确实昨天花了整整一天时间在谷歌上尝试并且我不知所措……

非常感谢任何帮助,以便我可以回到我的实际工作.

坦克很多提前.

作为参考:

我还发现了以下代码,它可以做什么,我想要什么,但是它是2D的,所以它对我没有帮助:

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)

如果觉得《python 3d绘图 拖动_使用python-matplotlib连续3D绘图(即图形更新)?》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。