refactor
This commit is contained in:
31
animation.py
Normal file
31
animation.py
Normal file
@ -0,0 +1,31 @@
|
||||
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)
|
||||
plt.show()
|
||||
source.disconnect()
|
||||
|
||||
def update(self, value=None, **kwargs):
|
||||
self.plot.set(value)
|
||||
plt.draw()
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user