Graphics¶
-
class
do_mpc.graphics.Graphics(data)[source]¶ Graphics module to present the results of do-mpc. The module is independent of all other modules and can be used optionally. The module can also be used with pickled result files in post-processing for flexible and custom graphics.
The graphics module is based on Matplotlib and allows for fully customizable, publication ready graphics and animations.
The Graphics module is initialized with an
do_mpc.data.Dataordo_mpc.data.MPCDatamodule and will showcase this data.User defined graphics are configured prior to plotting results, e.g.:
mpc = do_mpc.controller.MPC(model) ... # Initialize graphic: graphics = do_mpc.graphics.Graphics(mpc.data) # Create figure with arbitrary Matplotlib method fig, ax = plt.subplots(5, sharex=True) # Configure plot (pass the previously obtained ax objects): graphics.add_line(var_type='_x', var_name='C_a', axis=ax[0]) graphics.add_line(var_type='_x', var_name='C_b', axis=ax[0]) graphics.add_line(var_type='_x', var_name='T_R', axis=ax[1]) graphics.add_line(var_type='_x', var_name='T_K', axis=ax[1]) graphics.add_line(var_type='_aux', var_name='T_dif', axis=ax[2]) graphics.add_line(var_type='_u', var_name='Q_dot', axis=ax[3]) graphics.add_line(var_type='_u', var_name='F', axis=ax[4]) # Optional configuration of the plot(s) with matplotlib: ax[0].set_ylabel('c [mol/l]') ax[1].set_ylabel('Temperature [K]') ax[2].set_ylabel('\Delta T [K]') ax[3].set_ylabel('Q_heat [kW]') ax[4].set_ylabel('Flow [l/h]') fig.align_ylabels()
After initializing the
Graphicsmodule, theGraphics.add_line()method is used to define which results are to be plotted on which existing axes object. The method created (empty) line objects for each plotted variable. The graphic is updated with the most recent data withGraphics.plot_results(). Furthermore, the module contains theGraphics.plot_predictions()method which is applicable only fordo_mpc.data.MPCData, and can be used to show the predicted trajectories.Note
A high-level API for obtaining a configured
Graphicsmodule is thedefault_plot()function. Use this function and the obtainedGraphicsmodule in the developement process.Animations can be setup with the follwing loop:
for k in range(50): u0 = mpc.make_step(x0) y_next = simulator.make_step(u0) x0 = estimator.make_step(y_next) graphics.plot_results() graphics.plot_predictions() graphics.reset_axes() plt.show() plt.pause(0.01)
Parameters: data ( do_mpc.data.Dataordo_mpc.data.MPCData) – Data object from the do-mpc modules (simulator, estimator, controller)Attributes
Graphics.pred_linesStructure that holds the prediction line objects. Graphics.result_linesStructure that holds the result line objects. Methods
Graphics.add_lineadd_lineis called during setting up theGraphicsclass.Graphics.clearClears all data from lines. Graphics.plot_predictionsPlots the predicted trajectories for the plot configuration. Graphics.plot_resultsPlots the results stored in the data object. Graphics.reset_axesRelimits and scales all axes. Graphics.reset_prop_cycleResets the property cycle for all axes which were passed with Graphics.add_line().
This page is auto-generated. Page source is not available on Github.