Forum Archive

fig.canvas.flush_events() -> NotImplementedError

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()
JonB

Matplotlob on pythonista has some limitations, since it is not based on gtk, etc. So just the image back end.

I have an experimental pythonista back end, which allows interactive plots.

https://github.com/jsbain/backend_pythonista