|
| 1 | +from types import SimpleNamespace |
| 2 | + |
1 | 3 | import numpy as np |
| 4 | +import matplotlib.pyplot as plt |
2 | 5 | from casadi import DM |
3 | 6 |
|
4 | 7 | from bioptim import ( |
|
11 | 14 | InitialGuessList, |
12 | 15 | PlotType, |
13 | 16 | CustomPlot, |
| 17 | + Bounds, |
| 18 | + InterpolationType, |
14 | 19 | ) |
15 | 20 | from bioptim.gui.plot import DEFAULT_COLORS, PlotOcp |
16 | 21 |
|
@@ -91,6 +96,30 @@ def test_default_colors(): |
91 | 96 | assert PlotType.POINT in DEFAULT_COLORS |
92 | 97 |
|
93 | 98 |
|
| 99 | +def test_linear_bounds_are_plotted_with_linear_interpolation(): |
| 100 | + """Linear bounds must not be rendered as steps on integrated state plots.""" |
| 101 | + plot_ocp = PlotOcp.__new__(PlotOcp) |
| 102 | + plot_ocp.t = [np.linspace(0, 1, 3)] |
| 103 | + plot_ocp.plots_bounds = [] |
| 104 | + plot_ocp.plot_options = {"bounds": {"color": "k"}} |
| 105 | + |
| 106 | + bounds = Bounds( |
| 107 | + "q", |
| 108 | + min_bound=np.array([[0.0, 1.0]]), |
| 109 | + max_bound=np.array([[2.0, 4.0]]), |
| 110 | + interpolation=InterpolationType.LINEAR, |
| 111 | + ) |
| 112 | + nlp = SimpleNamespace(ns=2, plot={"q_states": SimpleNamespace(bounds=bounds)}) |
| 113 | + figure, axis = plt.subplots() |
| 114 | + |
| 115 | + plot_ocp._add_bounds_to_plot(0, nlp, "q_states", 0, axis, [0]) |
| 116 | + |
| 117 | + np.testing.assert_allclose(plot_ocp.plots_bounds[0][0][0].get_ydata(), [0.0, 0.5, 1.0]) |
| 118 | + np.testing.assert_allclose(plot_ocp.plots_bounds[1][0][0].get_ydata(), [2.0, 3.0, 4.0]) |
| 119 | + assert plot_ocp.plots_bounds[0][0][0].get_drawstyle() == "default" |
| 120 | + plt.close(figure) |
| 121 | + |
| 122 | + |
94 | 123 | def test_plot_options(): |
95 | 124 | """Test the plot options of PlotOcp""" |
96 | 125 | from tests.utils import TestUtils |
|
0 commit comments