• scoodood

    The following code works fine on my OSX. But it doesn't work on Pythonista. Why?
    Anyone know how to do dynamic update on Matplotlib? Thanks

    # import matplotlib
    # matplotlib.use('TkAgg')          # OSX need this
    
    import time
    import numpy as np
    import matplotlib.pyplot as plt
    
    plt.ion()
    
    class Plot:
        def __init__(self):
            self.deg = np.arange(0, 360, .1)
            self.rad = np.deg2rad(self.deg)
            self.cos = np.cos(self.rad)
            self.fig = plt.figure()
            self.ax = self.fig.add_subplot(111)
            self.ax.plot(self.deg, self.cos)
            self.ax.grid()
    
        def run(self, counter=100):
            for i in range(counter):
                self.cos = np.roll(self.cos, -30)
                self.ax.lines[0].set_xdata(self.deg)
                self.ax.lines[0].set_ydata(self.cos)
                self.fig.canvas.draw()
                self.fig.canvas.flush_events()
                time.sleep(.01)
    
    pp = Plot()
    pp.run()
    

    posted in Pythonista read more

Internal error.

Oops! Looks like something went wrong!