from matplotlib import pyplot as plt # expect from source: # - get() -> value # - name # - add_callback(cb) # - disconnect() # plot_func takes result of source.get() # returns Plot object # Plot object has set(val) class Animation: def __init__(self, source, plot_func): value = source.get() self.plot = plot_func(value) plt.suptitle(source.name) source.add_callback(self.update) try: plt.show() finally: print("disconnect:", source) source.disconnect() def update(self, value=None, **kwargs): self.plot.set(value) plt.draw()