JuliaControl / ControlSystems.jl

A Control Systems Toolbox for Julia
https://juliacontrol.github.io/ControlSystems.jl/stable/
Other
503 stars 85 forks source link

Change input/output plot order of SimResult #919

Closed scls19fr closed 4 months ago

scls19fr commented 4 months ago

Hello,

I think it will be more "logical" to first plot input and after output by default when both plotu and ploty are true

image

Code to reproduce:

using ControlSystems
using Plots
τ = 2.0  # s (time constant)
K = 1
s = tf("s")
T1 = K / (1 + τ * s)
t = 0:0.01:10
t0 = 1.0
u = 2.0 * (t .>= t0)'
res = lsim(T1, u, t)
plot(res, label=["output" "input"], plotu=true, ploty=true)

Called code https://github.com/JuliaControl/ControlSystems.jl/blob/0d825400f1fd0126a4ccaa63408ba2b38351d47a/lib/ControlSystemsBase/src/plotting.jl#L105

Kind regards

baggepinnen commented 4 months ago

The default is to not plot the input, so if the user requests this, it makes sense to add this plot after the existing one. Also, this is really a trivial thing and I see no point in changing this behavior and confuse existing users. Every figure caption produced by this plot recipe referring to the top or bottom plot pane would be invalid after such a change, breaking peoples notebooks etc., completely unnecessary in my opinion.

If you prefer a different order. you can easily override the default using

plot(step(P, 10), plotu=true, sp=[2 1])