Skip to content

Commit 9f60a71

Browse files
authored
Merge pull request #150 from control-toolbox/149-dev-plot-a-solution
Plot without positional arguments
2 parents 54255c0 + b68a9e4 commit 9f60a71

3 files changed

Lines changed: 57 additions & 3 deletions

File tree

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "CTModels"
22
uuid = "34c4fa32-2049-4079-8329-de33c2a22e2d"
33
authors = ["Olivier Cots <olivier.cots@toulouse-inp.fr>"]
4-
version = "0.4.1"
4+
version = "0.4.2"
55

66
[deps]
77
CTBase = "54762871-cc72-4466-b8e8-f6c8b58076cd"
@@ -34,7 +34,7 @@ JSON3 = "1.14"
3434
LinearAlgebra = "1"
3535
MLStyle = "0.4"
3636
MacroTools = "0.5"
37-
OrderedCollections = "1.8.0"
37+
OrderedCollections = "1.8"
3838
Parameters = "0.12"
3939
Plots = "1.40"
4040
PrettyTables = "2.4"

ext/plot.jl

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1112,6 +1112,47 @@ function Plots.plot!(
11121112
kwargs...,
11131113
)
11141114

1115+
model = CTModels.model(sol)
1116+
1117+
# check if the plot is empty
1118+
if isempty(p.series_list)
1119+
1120+
attr = NamedTuple((Symbol(key),value) for (key,value) in p.attr if key != :layout)
1121+
1122+
pnew = __initial_plot(
1123+
sol,
1124+
description...;
1125+
layout=layout,
1126+
control=control,
1127+
model=model,
1128+
size=__size_plot(
1129+
sol,
1130+
model,
1131+
control,
1132+
layout,
1133+
description...;
1134+
state_style=state_style,
1135+
control_style=control_style,
1136+
costate_style=costate_style,
1137+
path_style=path_style,
1138+
dual_style=dual_style,
1139+
),
1140+
state_style=state_style,
1141+
control_style=control_style,
1142+
costate_style=costate_style,
1143+
path_style=path_style,
1144+
dual_style=dual_style,
1145+
attr...,
1146+
kwargs...,
1147+
)
1148+
1149+
# replace p by pnew, must have a side effect
1150+
for k fieldnames(typeof(p))
1151+
setfield!(p, k, getfield(pnew, k))
1152+
end
1153+
1154+
end
1155+
11151156
# plot the solution with infos from the model
11161157
return __plot!(
11171158
p,
@@ -1124,7 +1165,7 @@ function Plots.plot!(
11241165
state_style=state_style,
11251166
control_style=control_style,
11261167
costate_style=costate_style,
1127-
model=CTModels.model(sol),
1168+
model=model,
11281169
state_bounds_style=state_bounds_style,
11291170
control_bounds_style=control_bounds_style,
11301171
time_style=time_style,

test/extras/plot_manual.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
using Pkg
2+
Pkg.activate(".")
3+
14
using CTModels
25
using Plots
36

@@ -37,6 +40,8 @@ function get_solution()
3740
end
3841
CTModels.definition!(pre_ocp, definition) # does not correspond to the solution
3942

43+
CTModels.time_dependence!(pre_ocp; autonomous=false)
44+
4045
# build model
4146
ocp = CTModels.build_model(pre_ocp)
4247

@@ -127,7 +132,15 @@ end;
127132

128133
sol = get_solution();
129134

135+
#
136+
plt = plot(size=(800,800))
137+
pp = plot!(plt, sol)
138+
139+
pp
140+
plt
141+
130142
# layout = :group
143+
131144
plot(sol; layout=:group, control=:components)
132145
plot(sol; layout=:group, control=:norm)
133146
plot(sol; layout=:group, control=:all)

0 commit comments

Comments
 (0)