Skip to content

Commit 2a25e13

Browse files
committed
fix size of ploté
1 parent 731755f commit 2a25e13

3 files changed

Lines changed: 33 additions & 24 deletions

File tree

ext/default.jl

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,30 @@ Used to set the default value of the plot size.
3030
function __size_plot(
3131
sol::CTModels.Solution,
3232
model::Union{CTModels.Model, Nothing},
33-
control::Symbol
33+
control::Symbol,
34+
layout::Symbol
3435
)
35-
n = CTModels.state_dimension(sol)
36-
l = @match control begin
37-
:components => CTModels.control_dimension(sol)
38-
:norm => 1
39-
:all => CTModels.control_dimension(sol) + 1
40-
_ => throw(
41-
CTBase.IncorrectArgument(
42-
"No such choice for control. Use :components, :norm or :all"
43-
),
44-
)
36+
if layout === :group
37+
if control === :all
38+
return (600, 560)
39+
else
40+
return (600, 280)
41+
end
42+
else
43+
n = CTModels.state_dimension(sol)
44+
l = @match control begin
45+
:components => CTModels.control_dimension(sol)
46+
:norm => 1
47+
:all => CTModels.control_dimension(sol) + 1
48+
_ => throw(
49+
CTBase.IncorrectArgument(
50+
"No such choice for control. Use :components, :norm or :all"
51+
),
52+
)
53+
end
54+
nc = model === nothing ? 0 : CTModels.dim_path_constraints_nl(model)
55+
return (600, 140 * (n + l + nc))
4556
end
46-
nc = model === nothing ? 0 : CTModels.dim_path_constraints_nl(model)
47-
return (600, 140 * (n + l + nc))
4857
end
4958

5059
"""

ext/plot.jl

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -564,8 +564,8 @@ function __plot!(
564564
cs = CTModels.state_constraints_box(model)
565565
is = 1
566566
for i in 1:length(cs[1])
567-
hline!(p[is + cs[2][i] - 1], [cs[1][i]]; color=4, linewidth=1, label=:none, z_order=:back, state_bounds_style...) # lower bound
568-
hline!(p[is + cs[2][i] - 1], [cs[3][i]], color=4, linewidth=1, label=:none, z_order=:back, state_bounds_style...) # upper bound
567+
hline!(p[is + cs[2][i] - 1], [cs[1][i]]; color=4, linewidth=1, label=:none, z_order=:back, series_attr..., state_bounds_style...) # lower bound
568+
hline!(p[is + cs[2][i] - 1], [cs[3][i]], color=4, linewidth=1, label=:none, z_order=:back, series_attr..., state_bounds_style...) # upper bound
569569
end
570570
end
571571

@@ -644,8 +644,8 @@ function __plot!(
644644
cu = CTModels.control_constraints_box(model)
645645
iu = 2n + 1
646646
for i in 1:length(cu[1])
647-
hline!(p[iu + cu[2][i] - 1], [cu[1][i]]; color=4, linewidth=1, label=:none, z_order=:back, control_bounds_style...) # lower bound
648-
hline!(p[iu + cu[2][i] - 1], [cu[3][i]], color=4, linewidth=1, label=:none, z_order=:back, control_bounds_style...) # upper bound
647+
hline!(p[iu + cu[2][i] - 1], [cu[1][i]]; color=4, linewidth=1, label=:none, z_order=:back, series_attr..., control_bounds_style...) # lower bound
648+
hline!(p[iu + cu[2][i] - 1], [cu[3][i]], color=4, linewidth=1, label=:none, z_order=:back, series_attr..., control_bounds_style...) # upper bound
649649
end
650650
end
651651

@@ -691,8 +691,8 @@ function __plot!(
691691

692692
# plot the lower and upper bounds for the path constraints
693693
for i in 1:nc
694-
hline!(p[ic + i - 1], [cp[1][i]]; color=4, linewidth=1, label=:none, z_order=:back, path_bounds_style...) # lower bound
695-
hline!(p[ic + i - 1], [cp[3][i]], color=4, linewidth=1, label=:none, z_order=:back, path_bounds_style...) # upper bound
694+
hline!(p[ic + i - 1], [cp[1][i]]; color=4, linewidth=1, label=:none, z_order=:back, series_attr..., path_bounds_style...) # lower bound
695+
hline!(p[ic + i - 1], [cp[3][i]], color=4, linewidth=1, label=:none, z_order=:back, series_attr..., path_bounds_style...) # upper bound
696696
end
697697
end
698698
else
@@ -717,7 +717,7 @@ function __plot!(
717717
end
718718
end
719719
for plt p.subplots
720-
vline!(plt, [t0, tf]; color=:black, linestyle=:dash, linewidth=1, label=:none, z_order=:back, time_style...)
720+
vline!(plt, [t0, tf]; color=:black, linestyle=:dash, linewidth=1, label=:none, z_order=:back, series_attr..., time_style...)
721721
end
722722
end
723723

@@ -750,9 +750,10 @@ function __plot(
750750
path_style::Tuple,
751751
path_bounds_style::Tuple,
752752
dual_path_style::Tuple,
753-
size=__size_plot(sol, model, control),
753+
size=__size_plot(sol, model, control, layout),
754754
kwargs...,
755755
)
756+
756757
p = __initial_plot(sol; layout=layout, control=control, model=model, size=size, kwargs...)
757758

758759
return __plot!(
@@ -839,11 +840,11 @@ function Plots.plot(
839840
layout::Symbol=__plot_layout(),
840841
control::Symbol=__control_layout(),
841842
time::Symbol=__time_normalization(),
842-
size=__size_plot(sol, nothing, control),
843843
solution_label::String=__plot_label_suffix(),
844844
state_style=__plot_style(),
845845
control_style=__plot_style(),
846846
costate_style=__plot_style(),
847+
size=__size_plot(sol, nothing, control, layout),
847848
kwargs...,
848849
)
849850
return __plot(
@@ -953,7 +954,7 @@ function Plots.plot(
953954
path_style::Tuple=__plot_style(),
954955
path_bounds_style::Tuple=__plot_style(),
955956
dual_path_style::Tuple=__plot_style(),
956-
size=__size_plot(sol, model, control),
957+
size=__size_plot(sol, model, control, layout),
957958
kwargs...,
958959
)
959960
return __plot(

test/extras/test_manual.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ include("../solution_example_path_constraints.jl")
88

99
ocp, sol = solution_example_path_constraints()
1010

11-
1211
#
1312
@test plot(sol; time=:default) isa Plots.Plot
1413
@test plot(sol; time=:normalize) isa Plots.Plot

0 commit comments

Comments
 (0)