Trying to update 3D coordinates using matplotlib

I have a function that will display a 3D sphere with matplotlib in tkinter. However, every time I call a function, performance when the sphere rotates rotates. Also, the chart is updated only after I try to rotate the sphere.

self.A is a variable that controls 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) 
+4
source share
1 answer

You do not have to restore all the data every time, but simply change your existing one.

Edit: just exit the axis-building code calling 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) 
+4
source

All Articles