Skip to content

Commit

Permalink
Merge pull request #183 from moorepants/plot-traj-with-no-inputs
Browse files Browse the repository at this point in the history
Handle no input trajectories.
  • Loading branch information
moorepants committed Jul 5, 2024
2 parents 507bc07 + e52e320 commit 82db878
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
7 changes: 7 additions & 0 deletions examples-gallery/plot_betts2003.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ def obj_grad(free):

plt.tight_layout()

# %%
fig_y2, axes_y2 = plt.subplots(3, 1)

axes_y2[0].plot(time, y2_m, '.k',
Expand All @@ -135,4 +136,10 @@ def obj_grad(free):

plt.tight_layout()

# %%
prob.plot_constraint_violations(solution)

# %%
prob.plot_trajectories(solution)

plt.show()
10 changes: 9 additions & 1 deletion opty/direct_collocation.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,15 @@ def plot_trajectories(self, vector, axes=None):
self.collocator.num_input_trajectories)
traj_syms = (self.collocator.state_symbols +
self.collocator.input_trajectories)
trajectories = np.vstack((state_traj, input_traj))

trajectories = state_traj

if self.collocator.num_known_input_trajectories > 0:
known_traj = list(self.collocator.known_trajectory_map.values())
trajectories = np.vstack((trajectories, known_traj))

if self.collocator.num_unknown_input_trajectories > 0:
trajectories = np.vstack((trajectories, input_traj))

if axes is None:
fig, axes = plt.subplots(num_axes, 1, sharex=True,
Expand Down

0 comments on commit 82db878

Please sign in to comment.