Skip to content

Commit 052aa52

Browse files
committed
can choose plot by desc
1 parent 5bdb366 commit 052aa52

4 files changed

Lines changed: 49 additions & 21 deletions

File tree

ext/default.jl

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,24 +79,35 @@ function __size_plot(
7979
end
8080
end
8181
if control == :all && nb_plots == 4
82-
return (600, 560)
82+
return (600, 420)
8383
else
8484
return (600, 280)
8585
end
8686
else
8787
n = CTModels.state_dimension(sol)
88+
m = CTModels.control_dimension(sol)
8889
l = @match control begin
89-
:components => CTModels.control_dimension(sol)
90+
:components => m
9091
:norm => 1
91-
:all => CTModels.control_dimension(sol) + 1
92+
:all => m + 1
9293
_ => throw(
9394
CTBase.IncorrectArgument(
9495
"No such choice for control. Use :components, :norm or :all"
9596
),
9697
)
9798
end
9899
nc = model === nothing ? 0 : CTModels.dim_path_constraints_nl(model)
99-
return (600, 140 * (n + l + nc))
100+
nb_lines = 0
101+
nb_lines += (:state description || :costate description) ? n : 0
102+
nb_lines += :control description ? l : 0
103+
nb_lines += (:cons description || :dual description) ? nc : 0
104+
if nb_lines==1
105+
return (600, 280)
106+
elseif nb_lines==2
107+
return (600, 420)
108+
else
109+
return (600, 140 * nb_lines)
110+
end
100111
end
101112

102113
end

ext/plot.jl

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ function __initial_plot(
231231
:control description && push!(plots, Plots.plot()) # control
232232
:control description && push!(plots, Plots.plot()) # control norm
233233
if length(plots) == 4
234-
return Plots.plot(plots...; layout=(2, 2), bottommargin=5mm, kwargs...)
234+
return Plots.plot(plots...; layout=(2, 2), kwargs...)
235235
else
236236
return Plots.plot(plots...; layout=(1, length(plots)), bottommargin=5mm, kwargs...)
237237
end
@@ -256,6 +256,9 @@ function __initial_plot(
256256
:costate description && push!(costate_plots, PlotLeaf())
257257
end
258258

259+
println("state_plots: ", state_plots)
260+
println("costate_plots: ", costate_plots)
261+
259262
# create the control plots
260263
if :control description
261264
l = m
@@ -284,10 +287,6 @@ function __initial_plot(
284287
end
285288
end
286289

287-
# starting root
288-
root = EmptyPlot()
289-
nblines = 0
290-
291290
# assemble the state and costate plots
292291
node_x = isempty(state_plots) ? EmptyPlot() : PlotNode(:column, state_plots)
293292
node_p = isempty(costate_plots) ? EmptyPlot() : PlotNode(:column, costate_plots)
@@ -301,6 +300,8 @@ function __initial_plot(
301300
node_u = isempty(control_plots) ? EmptyPlot() : PlotNode(:column, control_plots)
302301

303302
# create the root node
303+
root = EmptyPlot()
304+
nblines = 0
304305
if ( !(node_xp isa EmptyPlot) && !(node_u isa EmptyPlot) )
305306
nblines = n + l
306307
a = __height(round(n / nblines; digits=2))
@@ -309,9 +310,12 @@ function __initial_plot(
309310
b
310311
]
311312
root = PlotNode(lay, [node_xp, node_u])
312-
else
313-
root = node_xp isa EmptyPlot ? node_u : node_xp
314-
nblines = node_xp isa EmptyPlot ? l : n
313+
elseif !(node_xp isa EmptyPlot)
314+
root = node_xp
315+
nblines = n
316+
elseif !(node_u isa EmptyPlot)
317+
root = node_u
318+
nblines = l
315319
end
316320

317321
# Add the path constraints and their dual variables (in two columns as for state and costate) plots
@@ -336,8 +340,9 @@ function __initial_plot(
336340
end
337341

338342
# update the root node
339-
if !(node_cocp isa EmptyPlot)
340-
c = __height(round(nc / (nblines + nc); digits=2))
343+
if !(node_cocp isa EmptyPlot)
344+
nblines += nc
345+
c = __height(round(nc / nblines; digits=2))
341346
@eval lay = @layout [
342347
a
343348
$c
@@ -347,7 +352,7 @@ function __initial_plot(
347352
end
348353

349354
# plot
350-
return __plot_tree(root; kwargs...)
355+
return nblines==1 ? __plot_tree(root; bottommargin=5mm, kwargs...) : __plot_tree(root; kwargs...)
351356

352357
else
353358
throw(CTBase.IncorrectArgument("No such choice for layout. Use :group or :split"))

test/extras/plot_duals.jl

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,19 @@ end;
6262
sol = SOL(ocp, t0, tf);
6363

6464
plt = plot(sol, ocp)
65+
plt = plot(sol, ocp, :state)
66+
plt = plot(sol, ocp, :state, :costate)
67+
plt = plot(sol, ocp, :state, :control)
68+
plt = plot(sol, ocp, :state, :control, :constraint)
69+
plt = plot(sol, ocp, :costate)
70+
plt = plot(sol, ocp, :control)
71+
plt = plot(sol, ocp, :constraint)
72+
plt = plot(sol, ocp, :dual)
73+
plt = plot(sol, ocp, :constraint, :dual)
6574

66-
mixed_con_dual = CTModels.dual(sol, ocp, :mixed_con)
67-
plot(range(t0, tf; length=101), mixed_con_dual)
75+
# mixed_con_dual = CTModels.dual(sol, ocp, :mixed_con)
76+
# plot(range(t0, tf; length=101), mixed_con_dual)
6877

69-
eq2_dual = CTModels.dual(sol, ocp, :eq2)
70-
plot(range(t0, tf; length=101), t -> eq2_dual(t)[1]; label="eq2_dual 1")
71-
plot!(range(t0, tf; length=101), t -> eq2_dual(t)[2]; label="eq2_dual 2")
78+
# eq2_dual = CTModels.dual(sol, ocp, :eq2)
79+
# plot(range(t0, tf; length=101), t -> eq2_dual(t)[1]; label="eq2_dual 1")
80+
# plot!(range(t0, tf; length=101), t -> eq2_dual(t)[2]; label="eq2_dual 2")

test/extras/plot_manual.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,9 @@ end;
129129
sol = get_solution();
130130

131131
# layout = :group
132-
plot(sol; layout=:group)
132+
plot(sol; layout=:group, control=:components)
133+
plot(sol; layout=:group, control=:norm)
134+
plot(sol; layout=:group, control=:all)
133135
plot(sol, :state; layout=:group)
134136
plot(sol, :costate; layout=:group)
135137
plot(sol, :control; layout=:group)
@@ -147,6 +149,7 @@ plot(sol, :control; layout=:split, control=:norm)
147149
plot(sol, :state, :control; layout=:split)
148150
plot(sol, :control; layout=:split, control=:all)
149151
plot(sol, :state, :control; layout=:split, control=:all)
152+
plot(sol, :state, :costate; layout=:split)
150153
nothing
151154
# plt = plot(sol; size=(700, 450), time=:normalise)
152155

0 commit comments

Comments
 (0)