Add animation mode to PlotHelper
As discussed at one point, it would be very nice to let the PlotHelper
also handle matplotlib animations.
A use case could look like this:
@is_plot_func(creator_type=ExternalPlotCreator, defaults="my_plot_func_defaults.yml",
use_helper=True, supports_animation=True)
def my_plot_func(dm: DataManager, *, hlpr: PlotHelper, t0: int=0, **kwargs):
# Regular plot function
data_y = dm["data_y"]
plt.plot(dm["data_x"], data_y[t0])
# ... which could end here
# But it defines a locally scoped update function, a so-called Python Generator (using yield)
def update():
for row in data_y[t0:]:
hlpr.ax.yaxis.set_data(row) # or however that syntax is
yield
# Register the update function with the helper
hlpr.register_animation_update(update)
# End of plot function. The helper then calls the generator and saves each frame, until no frames are left.
The PlotHelper
would then take care of using the update function to grab the frames.
To allow frame-by-frame saving, it might make sense to add the FramesWriter
from utopya into dantro...
People involved
Edited by Utopia Developers