尝试使用 matplotlib 更新 3D 图形坐标
我有一个函数可以在 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)
I have a function that will graph a 3D sphere with matplotlib in tkinter. 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.
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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不应该每次都重新生成所有数据,而只需修改现有数据即可。
编辑:只需移出调用draw_fig 轴构建代码
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