我有一个函数可以在tkinter中使用matplotlib绘制3D球体。然而,每次连续的时间我都会在旋转球体时调用该函数的性能下降。此图仅在我尝试围绕球体运行后更新。
self.A 是一个调整球体大小的变量。
我的功能:
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)
答案 0 :(得分:4)
您不应每次都重新生成所有数据,而只需修改现有数据。
编辑:刚刚移出调用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)