Skip to content

Resolve "Add animation mode to PlotHelper"

Utopia Developers requested to merge 64-add-animation-mode-to-plothelper into master

What does this MR do?

Add animation mode to PlotHelper.

Every plot function will be able to (optionally) define an animation. This is simply done by defining a generator 'animation_update'. This specifies the data to plot each frame.

The animation mode should support different MovieWriters (i.e. saving-by-frame with FileWriter).

A use case could look like this:

@is_plot_func(creator_type=ExternalPlotCreator, supports_animation=True)
def my_plot_func(dm: DataManager, *, hlpr: PlotHelper, **kwargs):
    # Regular plot function
    data_y = dm["data_y"]
    plt.plot(dm["data_x"], data_y[-1])

    # ... which could end here

    # But it additionally defines a locally scoped update function, a so-called Python Generator (using yield)
    indices = range(100)

    def update():
        for i in indices:
            hlpr.ax.clean() # clean the axis as previous plot would be overwritten otherwise
            hlpr.ax.plot(dm["data_x"], data_y[i])
            yield

    # Register the update function with the helper
    hlpr.register_animation_update(update)

    # End of plot function. For an animation the helper then calls the generator and saves each frame,
    # until no frames are left.

Note that the update function can be adapted in many ways (i.e. invoke additional helpers, adapt data to plot, stack plots etc.).

Can this MR be accepted?

  • Implemented the feature
  • Tests added or adjusted
  • Full test coverage
  • Pipeline passes
  • Changelog entry added
  • Version number bumped
  • Approved by @jeremiastraub
  • Approved by @blsqr

Anything to double-check?

Related issues

Closes #64 (closed)

Edited by Utopia Developers

Merge request reports