direct_data_driven_mpc.utilities.visualization.comparison_plot#
Functions for plotting multiple input-output data for control system comparison.
This module provides functions for plotting multiple input-output trajectories with setpoints using Matplotlib. It enables comparing different control systems by plotting their control data in the same figure.
Functions
|
Plot multiple input-output trajectories with setpoints in a Matplotlib figure for control system comparison. |
|
Validate that input/output data and plot parameter lists match the expected dimensions for generating comparison plots. |
- plot_input_output_comparison(u_data: list[ndarray], y_data: list[ndarray], y_s: ndarray, u_s: ndarray | None = None, u_bounds_list: list[tuple[float, float]] | None = None, y_bounds_list: list[tuple[float, float]] | None = None, inputs_line_param_list: list[dict[str, Any]] | None = None, outputs_line_param_list: list[dict[str, Any]] | None = None, setpoints_line_params: dict[str, Any] | None = None, bounds_line_params: dict[str, Any] | None = None, var_suffix_list: list[str] | None = None, legend_params: dict[str, Any] | None = None, figsize: tuple[int, int] = (14, 8), dpi: int = 300, u_ylimits_list: list[tuple[float, float]] | None = None, y_ylimits_list: list[tuple[float, float]] | None = None, fontsize: int = 12, title: str | None = None, input_labels: list[str] | None = None, output_labels: list[str] | None = None, u_setpoint_labels: list[str] | None = None, y_setpoint_labels: list[str] | None = None, x_axis_labels: list[str] | None = None, input_y_axis_labels: list[str] | None = None, output_y_axis_labels: list[str] | None = None, show: bool = True) None [source]#
Plot multiple input-output trajectories with setpoints in a Matplotlib figure for control system comparison.
This function creates a figure with two rows of subplots: the first row for control inputs, and the second for system outputs. Each subplot shows the trajectories of each data series alongside its setpoint line. Useful for comparing the performance of different control systems.
- Parameters:
u_data (
list[np.ndarray]
) – A list of M arrays of shape (T, m) containing control input data from M simulations. T is the number of time steps, and m is the number of control inputs.y_data (
list[np.ndarray]
) – A list of M arrays of shape (T, p) containing system output data from M simulations. T is the number of time steps, and p is the number of system outputs.y_s (
numpy.ndarray
) – An array of shape (T, p) containing p output setpoint values. These setpoints correspond to the system outputs from y_data.u_s (
np.ndarray | None
) – An array of shape (T, m) containing m input setpoint values. These setpoints correspond to the control inputs from u_data. If None, input setpoint lines will not be plotted. Defaults to None.u_bounds_list (
list[tuple[float
,float]] | None
) – A list of tuples (lower_bound, upper_bound) specifying bounds for each input data sequence. If provided, horizontal lines representing these bounds will be plotted in each subplot. If None, no horizontal lines will be plotted. The number of tuples must match the number of input data sequences. Defaults to None.y_bounds_list (
list[tuple[float
,float]] | None
) – A list of tuples (lower_bound, upper_bound) specifying bounds for each output data sequence. If provided, horizontal lines representing these bounds will be plotted in each subplot. If None, no horizontal lines will be plotted. The number of tuples must match the number of output data sequences. Defaults to None.inputs_line_param_list (
list[dict[str
,Any]] | None
) – A list of M dictionaries, where each dictionary specifies Matplotlib properties for customizing the plot lines corresponding to one of the M input data arrays in u_data. If not provided, Matplotlib’s default line properties will be used.outputs_line_param_list (
list[dict[str
,Any]] | None
) – A list of M dictionaries, where each dictionary specifies Matplotlib properties for customizing the plot lines corresponding to one of the M output data arrays in y_data. If not provided, Matplotlib’s default line properties will be used.setpoints_line_params (
dict[str
,Any] | None
) – A dictionary of Matplotlib properties for customizing the lines used to plot the setpoint values (e.g., color, linestyle, linewidth). If not provided, Matplotlib’s default line properties will be used.bounds_line_params (
dict[str
,Any] | None
) – A dictionary of Matplotlib properties for customizing the lines used to plot the bounds of input-output data series (e.g., color, linestyle, linewidth). If not provided, Matplotlib’s default line properties will be used.var_suffix_list (
list[str] | None
) – A list of strings appended to each data series label in the plot legend. If not provided, no strings are appended.legend_params (
dict[str
,Any] | None
) – A dictionary of Matplotlib properties for customizing the plot legends (e.g., fontsize, loc, handlelength). If not provided, Matplotlib’s default legend properties will be used.figsize (
tuple[int
,int]
) – The (width, height) dimensions of the created Matplotlib figure.dpi (
int
) – The DPI resolution of the figure.u_ylimits_list (
list[tuple[float
,float]] | None
) – A list of tuples (lower_limit, upper_limit) specifying the Y-axis limits for each input subplot. If None, the Y-axis limits will be determined automatically.y_ylimits_list (
list[tuple[float
,float]] | None
) – A list of tuples (lower_limit, upper_limit) specifying the Y-axis limits for each output subplot. If None, the Y-axis limits will be determined automatically.fontsize (
int
) – The fontsize for labels, legends and axes ticks.title (
str | None
) – The title for the created plot figure.input_labels (
list[str] | None
) – A list of strings specifying custom legend labels for input data series. If provided, the label at each index will override the default label constructed using var_suffix_list.output_labels (
list[str] | None
) – A list of strings specifying custom legend labels for output data series. If provided, the label at each index will override the default label constructed using var_suffix_list.u_setpoint_labels (
list[str] | None
) – A list of strings specifying custom legend labels for input setpoint series. If provided, the label at each index will override the corresponding default label.y_setpoint_labels (
list[str] | None
) – A list of strings specifying custom legend labels for output setpoint series. If provided, the label at each index will override the corresponding default label.x_axis_labels (
list[str] | None
) – A list of strings specifying custom X-axis labels for each subplot. If provided, the label at each index will override the corresponding default label.input_y_axis_labels (
list[str] | None
) – A list of strings specifying custom Y-axis labels for each input subplot. If provided, the label at each index will override the corresponding default label.output_y_axis_labels (
list[str] | None
) – A list of strings specifying custom Y-axis labels for each output subplot. If provided, the label at each index will override the corresponding default label.show (
bool
) – Whether to call plt.show() for the figure or not. Useful when adding plot elements externally before rendering the figure. Defaults to True.
- Raises:
ValueError – If input/output array shapes, or line parameter list lengths, are not as expected.
- validate_comparison_plot_parameters(u_data: list[ndarray], y_data: list[ndarray], inputs_line_param_list: list[dict[str, Any]] | None = None, outputs_line_param_list: list[dict[str, Any]] | None = None, var_suffix_list: list[str] | None = None, input_labels: list[str] | None = None, output_labels: list[str] | None = None) None [source]#
Validate that input/output data and plot parameter lists match the expected dimensions for generating comparison plots.
- Parameters:
u_data (
list[np.ndarray]
) – A list of M arrays of shape (T, m) containing control input data from M simulations. T is the number of time steps, and m is the number of control inputs.y_data (
list[np.ndarray]
) – A list of M arrays of shape (T, p) containing system output data from M simulations. T is the number of time steps, and p is the number of system outputs.inputs_line_param_list (
list[dict[str
,Any]] | None
) – A list of M dictionaries, where each dictionary specifies Matplotlib properties for customizing the plot lines corresponding to one of the M input data arrays in u_data.outputs_line_param_list (
list[dict[str
,Any]] | None
) – A list of M dictionaries, where each dictionary specifies Matplotlib properties for customizing the plot lines corresponding to one of the M output data arrays in y_data.var_suffix_list (
list[str] | None
) – A list of strings appended to each data series label in the plot legend.input_labels (
list[str] | None
) – A list of strings specifying custom legend labels for input data series.output_labels (
list[str] | None
) – A list of strings specifying custom legend labels for output data series.
- Raises:
ValueError – If any parameter does not match the expected dimension.