def toggle(self, ax=None):
        """Creates a play/pause button to start/stop the animation

        Parameters
        ----------
        ax : matplotlib.axes.Axes, optional
            The matplotlib axes to attach the button to.
        """
        if ax is None:
            adjust_plot = {'bottom': .2}
            rect = [.78, .03, .1, .07]

            plt.subplots_adjust(**adjust_plot)
            self.button_ax = plt.axes(rect)
        else:
            self.button_ax = ax

        self.button = Button(self.button_ax, "Pause")
        self.button.label2 = self.button_ax.text(
            0.5, 0.5, 'Play',
            verticalalignment='center',
            horizontalalignment='center',
            transform=self.button_ax.transAxes
        )
        self.button.label2.set_visible(False)

        def pause(event):
            if self._pause:
                self.animation.event_source.start()
                self.button.label.set_visible(True)
                self.button.label2.set_visible(False)
            else:
                self.animation.event_source.stop()
                self.button.label.set_visible(False)
                self.button.label2.set_visible(True)
            self.fig.canvas.draw()
            self._pause ^= True
        self.button.on_clicked(pause)
def toggle ( self , ax = None ) : if ax is None : adjust_plot = { 'bottom' : .2 } rect = [ .78 , .03 , .1 , .07 ] plt . subplots_adjust ( ** adjust_plot ) self . button_ax = plt . axes ( rect ) else : self . button_ax = ax self . button = Button ( self . button_ax , "Pause" ) self . button . label2 = self . button_ax . text ( 0.5 , 0.5 , 'Play' , verticalalignment = 'center' , horizontalalignment = 'center' , transform = self . button_ax . transAxes ) self . button . label2 . set_visible ( False ) def pause ( event ) : if self . _pause : self . animation . event_source . start ( ) self . button . label . set_visible ( True ) self . button . label2 . set_visible ( False ) else : self . animation . event_source . stop ( ) self . button . label . set_visible ( False ) self . button . label2 . set_visible ( True ) self . fig . canvas . draw ( ) self . _pause ^= True self . button . on_clicked ( pause )
Creates a play/pause button to start/stop the animation

        Parameters
        ----------
        ax : matplotlib.axes.Axes, optional
            The matplotlib axes to attach the button to.