[英]Trying to update a 3D graphs coordinates with matplotlib
I have a function that will graph a 3D sphere with matplotlib in tkinter. 我有一个函数,它将在tkinter中使用matplotlib绘制3D球体。 However, every successive time I call the function the performance when orbiting the sphere drops.
然而,每次连续的时间我都会在旋转球体时调用该函数的性能下降。 Also the graph only updates after I try to orbit the sphere.
此图仅在我尝试围绕球体运行后更新。
self.A is a variable that adjusts the size of the sphere. self.A是一个调整球体大小的变量。
My function: 我的功能:
def draw_fig(self):
self.ax = Axes3D(self.fig)
u = numpy.linspace(0, 2 * numpy.pi, 100)
v = numpy.linspace(0, numpy.pi, 100)
x = self.A * numpy.outer(numpy.cos(u), numpy.sin(v))
y = self.A * numpy.outer(numpy.sin(u), numpy.sin(v))
z = self.A * numpy.outer(numpy.ones(numpy.size(u)), numpy.cos(v))
t = self.ax.plot_surface(x, y, z, rstride=4, cstride=4,color='lightblue',linewidth=0)
You should not regenerate each time all the data, but just modify your existing one. 您不应每次都重新生成所有数据,而只需修改现有数据。
Edit: Just move out of the calling draw_fig the axes building code 编辑:刚刚移出调用draw_fig的轴构建代码
def __init__...
u = numpy.linspace(0, 2 * numpy.pi, 100)
v = numpy.linspace(0, numpy.pi, 100)
self.x = A * numpy.outer(numpy.cos(u), numpy.sin(v))
self.y = A * numpy.outer(numpy.sin(u), numpy.sin(v))
self.z = A * numpy.outer(numpy.ones(numpy.size(u)), numpy.cos(v))
self.ax = Axes3D(self.fig)
def draw_fig(self):
t = self.ax.plot_surface(self.x, self.y, self.z, rstride=4, cstride=4,color='lightblue',linewidth=0)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.