15 from proxsuite_nlp.utils
import plot_pd_errs
17 prim_infeas = cb.prim_infeas.tolist()
18 dual_infeas = cb.dual_infeas.tolist()
20 prim_infeas.append(res.primal_infeas)
21 dual_infeas.append(res.dual_infeas)
22 plot_pd_errs(ax, prim_infeas, dual_infeas)
23 ax.grid(axis=
"y", which=
"major")
24 handles, labels = ax.get_legend_handles_labels()
30 prim_tols = np.array(cb.prim_tols)
31 al_iters = np.array(cb.al_index)
32 labels.append(
"$\\eta_k$")
34 itrange = np.arange(len(al_iters))
36 if al_iters.max() > 0:
37 labels.append(
"AL iters")
38 ax.step(itrange, prim_tols, c=
"green", alpha=0.9, lw=1.1)
39 al_change = al_iters[1:] - al_iters[:-1]
40 al_change_idx = itrange[:-1][al_change > 0]
42 ax.vlines(al_change_idx, *ax.get_ylim(), colors=
"gray", lw=4.0, alpha=0.5)
44 ax.legend(labels=labels, **legend_kwargs)
49 q: np.ndarray, ax: plt.Axes, alpha=0.5, fc=
"tab:blue"
51 from matplotlib
import transforms
55 center = (q[0] - 0.5 * w, q[1] - 0.5 * h)
56 rect = plt.Rectangle(center, w, h, fc=fc, alpha=alpha)
57 theta = np.arctan2(q[3], q[2])
58 transform_ = transforms.Affine2D().rotate_around(*q[:2], -theta) + ax.transData
59 rect.set_transform(transform_)
82) -> tuple[plt.Figure, list[plt.Axes]]:
87 nrows, r = divmod(nu, ncols)
90 make_new_plot = axes
is None
92 fig, axes = plt.subplots(nrows, ncols, sharex=
"col", figsize=figsize)
94 fig = axes.flat[0].get_figure()
97 if rmodel
is not None:
98 effort_limit = rmodel.effortLimit
99 joint_names = rmodel.names
102 ax: plt.Axes = axes[i]
103 ax.step(times[:-1], us[:, i])
104 if effort_limit
is not None:
106 ax.hlines(-effort_limit[i], t0, tf, colors=
"k", linestyles=
"--")
107 ax.hlines(+effort_limit[i], t0, tf, colors=
"r", linestyles=
"dashdot")
109 if joint_names
is not None:
110 joint_name = joint_names[i].lower()
111 ax.set_title(joint_name, fontsize=8)
113 fig.supxlabel(xlabel)
114 fig.suptitle(
"Control trajectories")
116 axes[0].set_xlabel(xlabel)
117 axes[0].set_title(
"Control trajectories")
131) -> tuple[plt.Figure, list[plt.Axes]]:
134 assert nv == vs.shape[1]
135 if vel_limit
is not None:
136 assert nv == vel_limit.shape[0]
137 idx_to_joint_id_map = {}
140 if i
in rmodel.idx_vs.tolist():
142 idx_to_joint_id_map[i] = jid
143 nrows, r = divmod(nv, ncols)
150 fig, axes = plt.subplots(nrows, ncols, sharex=
True, figsize=figsize)
153 fig = axes.flat[0].get_figure()
157 ax: plt.Axes = axes[i]
158 ax.plot(times, vs[:, i])
159 jid = idx_to_joint_id_map[i]
160 joint_name = rmodel.names[jid].lower()
161 if vel_limit
is not None:
163 ax.hlines(-vel_limit[i], t0, tf, colors=
"k", linestyles=
"--")
164 ax.hlines(+vel_limit[i], t0, tf, colors=
"r", linestyles=
"dashdot")
166 ax.set_title(joint_name, fontsize=8)
168 fig.supxlabel(xlabel)
169 fig.suptitle(
"Velocity trajectories")
tuple[plt.Figure, list[plt.Axes]] plot_controls_traj(times, us, ncols=2, axes=None, effort_limit=None, joint_names=None, rmodel=None, figsize=(6.4, 6.4), xlabel="Time (s)")
tuple[plt.Figure, list[plt.Axes]] plot_velocity_traj(times, vs, rmodel, axes=None, ncols=2, vel_limit=None, figsize=(6.4, 6.4), xlabel="Time (s)")