Using Plots

All plotting requires the user to manually load the Plots.jl library, e.g., by calling using Plots.

Time-domain responses

There are no special functions to plot time-domain results, such as step and impulse responses, instead, simply call plot on the result structure (ControlSystemsBase.SimResult) returned by lsim, step, impulse etc.

# Plotting functions

ControlSystemsBase.bodeplotFunction
fig = bodeplot(sys, args...)
bodeplot(LTISystem[sys1, sys2...], args...; plotphase=true, balance = true, kwargs...)

Create a Bode plot of the LTISystem(s). A frequency vector w can be optionally provided. To change the Magnitude scale see setPlotScale. The default magnitude scale is "log10" (absolute scale).

• If hz=true, the plot x-axis will be displayed in Hertz, the input frequency vector is still treated as rad/s.
• balance: Call balance_statespace on the system before plotting.

kwargs is sent as argument to RecipesBase.plot.

source
ControlSystemsBase.marginplotFunction
fig = marginplot(sys::LTISystem [,w::AbstractVector];  balance=true, kwargs...)
marginplot(sys::Vector{LTISystem}, w::AbstractVector;  balance=true, kwargs...)

Plot all the amplitude and phase margins of the system(s) sys.

kwargs is sent as argument to RecipesBase.plot.

source
ControlSystemsBase.nicholsplotFunction
fig = nicholsplot{T<:LTISystem}(systems::Vector{T}, w::AbstractVector; kwargs...)

Create a Nichols plot of the LTISystem(s). A frequency vector w can be optionally provided.

Keyword arguments:

text = true
Gains = [12, 6, 3, 1, 0.5, -0.5, -1, -3, -6, -10, -20, -40, -60]
pInc = 30
sat = 0.4
val = 0.85
fontsize = 10

pInc determines the increment in degrees between phase lines.

sat ∈ [0,1] determines the saturation of the gain lines

val ∈ [0,1] determines the brightness of the gain lines

Additional keyword arguments are sent to the function plotting the systems and can be used to specify colors, line styles etc. using regular RecipesBase.jl syntax

This function is based on code subject to the two-clause BSD licence Copyright 2011 Will Robertson Copyright 2011 Philipp Allgeuer

source
ControlSystemsBase.nyquistplotFunction
fig = nyquistplot(sys;                Ms_circles=Float64[], Mt_circles=Float64[], unit_circle=false, hz=false, critical_point=-1, kwargs...)
nyquistplot(LTISystem[sys1, sys2...]; Ms_circles=Float64[], Mt_circles=Float64[], unit_circle=false, hz=false, critical_point=-1, kwargs...)

Create a Nyquist plot of the LTISystem(s). A frequency vector w can be optionally provided.

• unit_circle: if the unit circle should be displayed. The Nyquist curve crosses the unit circle at the gain crossover frequency.
• Ms_circles: draw circles corresponding to given levels of sensitivity (circles around -1 with radii 1/Ms). Ms_circles can be supplied as a number or a vector of numbers. A design staying outside such a circle has a phase margin of at least 2asin(1/(2Ms)) rad and a gain margin of at least Ms/(Ms-1).
• Mt_circles: draw circles corresponding to given levels of complementary sensitivity. Mt_circles can be supplied as a number or a vector of numbers.
• critical_point: point on real axis to mark as critical for encirclements
• If hz=true, the hover information will be displayed in Hertz, the input frequency vector is still treated as rad/s.
• balance: Call balance_statespace on the system before plotting.

kwargs is sent as argument to plot.

source
ControlSystemsBase.pzmapFunction
fig = pzmap(fig, system, args...; hz = false, kwargs...)

Create a pole-zero map of the LTISystem(s) in figure fig, args and kwargs will be sent to the scatter plot command.

To customize the unit-circle drawn for discrete systems, modify the line attributes, e.g., linecolor=:red.

If hz is true, all poles and zeros are scaled by 1/2π.

source
ControlSystemsBase.rgaplotFunction
rgaplot(sys, args...; hz=false)
rgaplot(LTISystem[sys1, sys2...], args...; hz=false, balance=true)

Plot the relative-gain array entries of the LTISystem(s). A frequency vector w can be optionally provided.

• If hz=true, the plot x-axis will be displayed in Hertz, the input frequency vector is still treated as rad/s.
• balance: Call balance_statespace on the system before plotting.

kwargs is sent as argument to Plots.plot.

source
ControlSystemsBase.setPlotScaleMethod
setPlotScale(str)

Set the default scale of magnitude in bodeplot and sigmaplot. str should be either "dB" or "log10". The default scale if none is chosen is "log10".

source
ControlSystemsBase.sigmaplotFunction
sigmaplot(sys, args...; hz=false balance=true, extrema)
sigmaplot(LTISystem[sys1, sys2...], args...; hz=false, balance=true, extrema)

Plot the singular values of the frequency response of the LTISystem(s). A frequency vector w can be optionally provided.

• If hz=true, the plot x-axis will be displayed in Hertz, the input frequency vector is still treated as rad/s.
• balance: Call balance_statespace on the system before plotting.
• extrema: Only plot the largest and smallest singular values.

kwargs is sent as argument to Plots.plot.

source

## Examples

### Bode plot

tf1 = tf([1],[1,1])
tf2 = tf([1/5,2],[1,1,1])
sys = [tf1 tf2]
ws = exp10.(range(-2,stop=2,length=200))
bodeplot(sys, ws)

### Sigma plot

sys = ss([-1 2; 0 1], [1 0; 1 1], [1 0; 0 1], [0.1 0; 0 -0.2])
sigmaplot(sys)

### Margin

tf1 = tf([1],[1,1])
tf2 = tf([1/5,2],[1,1,1])
ws = exp10.(range(-2,stop=2,length=200))
marginplot([tf1, tf2], ws)

### Gangoffour plot

tf1 = tf([1.0],[1,1])
gangoffourplot(tf1, [tf(1), tf(5)])

### Nyquist plot

sys = ss([-1 2; 0 1], [1 0; 1 1], [1 0; 0 1], [0.1 0; 0 -0.2])
ws = exp10.(range(-2,stop=2,length=200))
nyquistplot(sys, ws, Ms_circles=1.2, Mt_circles=1.2)

### Nichols plot

tf1 = tf([1],[1,1])
ws = exp10.(range(-2,stop=2,length=200))
nicholsplot(tf1,ws)

### Pole-zero plot

tf2 = tf([1/5,2],[1,1,1])
pzmap(c2d(tf2, 0.1))

### Lsim response plot

sys = ss([-1 2; 0 1], [1 0; 1 1], [1 0; 0 1], [0.1 0; 0 -0.2])
sysd = c2d(sys, 0.01)
L = lqr(sysd, [1 0; 0 1], [1 0; 0 1])
ts = 0:0.01:5
plot(lsim(sysd, (x,i)->-L*x, ts; x0=[1;2]), plotu=true)

### Impulse response plot

tf1 = tf([1],[1,1])
tf2 = tf([1/5,2],[1,1,1])
sys = [tf1 tf2]
sysd = c2d(ss(sys), 0.01)
plot(impulse(sysd, 5), l=:blue)

### Step response plot

tf1 = tf([1],[1,1])
tf2 = tf([1/5,2],[1,1,1])
sys = [tf1 tf2]
sysd = c2d(ss(sys), 0.01)
res = step(sysd, 5)
plot(res, l=(:dash, 4))
# plot!(stepinfo(step(sysd[1,1], 5))) # adds extra info to the plot