@@ -55,14 +55,15 @@ function lsimplot{T<:StateSpace}(systems::Vector{T}, u::Union{AbstractVecOrMat,F
55
55
error (" All systems must have the same input/output dimensions" )
56
56
end
57
57
ny, nu = size (systems[1 ])
58
- fig = Plots. subplot (n= ny, nr= ny)
58
+ fig = Plots. plot (layout= (ny,1 ))
59
+ s2i (i,j) = sub2ind ((ny,1 ),j,i)
59
60
for (si, s) in enumerate (systems)
60
61
y = lsim (s, u, t, x0, method)[1 ]
61
62
for i= 1 : ny
62
63
ydata = reshape (y[:, i], size (t, 1 ))
63
64
style = iscontinuous (s) ? :path : :steppost
64
65
ytext = (ny > 1 ) ? " Amplitude to: y($i )" : " Amplitude"
65
- Plots. plot! (fig[i, 1 ], t, ydata, l= style, xlabel= " Time (s)" , ylabel= ytext, title= " System Response" , lab= " \$ G_\{ $(si) \}\$ " ; getStyleSys (si,length (systems))... , kwargs... )
66
+ Plots. plot! (fig, t, ydata, l= style, xlabel= " Time (s)" , ylabel= ytext, title= " System Response" , subplot = s2i ( 1 ,i), lab= " \$ G_\{ $(si) \}\$ " ; getStyleSys (si,length (systems))... , kwargs... )
66
67
end
67
68
end
68
69
return fig
@@ -80,7 +81,9 @@ for (func, title) = ((:step, "Step Response"), (:impulse, "Impulse Response"))
80
81
error (" All systems must have the same input/output dimensions" )
81
82
end
82
83
ny, nu = size (systems[1 ])
83
- fig = Plots. subplot (n = ny* nu, nr = ny)
84
+ fig = Plots. plot (layout= (ny,nu))
85
+ titles = fill (" " , ny* nu)
86
+ s2i (i,j) = sub2ind ((ny,nu),j,i)
84
87
for (si,(s, Ts)) in enumerate (zip (systems, Ts_list))
85
88
t = 0 : Ts: Tf
86
89
y = ($ func)(s, t)[1 ]
@@ -89,11 +92,13 @@ for (func, title) = ((:step, "Step Response"), (:impulse, "Impulse Response"))
89
92
ydata = reshape (y[:, i, j], size (t, 1 ))
90
93
style = iscontinuous (s) ? :path : :steppost
91
94
ttext = (nu > 1 && i== 1 ) ? $ title* " from: u($j ) " : $ title
95
+ titles[s2i (i,j)] = ttext
92
96
ytext = (ny > 1 && j== 1 ) ? " Amplitude to: y($i )" : " Amplitude"
93
- Plots. plot! (fig[i,j], t, ydata, l= style, xlabel= " Time (s)" , ylabel= ytext, title = ttext , lab= " \$ G_\{ $(si) \}\$ " ; getStyleSys (si,length (systems))... , kwargs... )
97
+ Plots. plot! (fig, t, ydata, l= style, xlabel= " Time (s)" , ylabel= ytext, subplot = s2i (i,j) , lab= " \$ G_\{ $(si) \}\$ " ; getStyleSys (si,length (systems))... , kwargs... )
94
98
end
95
99
end
96
100
end
101
+ Plots. plot! (fig, title= titles' )
97
102
return fig
98
103
end
99
104
$ funcname {T<:LTISystem} (systems:: Vector{T} , Tf:: Real ; kwargs... ) =
@@ -129,7 +134,8 @@ function bodeplot{T<:LTISystem}(systems::Vector{T}, w::AbstractVector; plotphase
129
134
error (" All systems must have the same input/output dimensions" )
130
135
end
131
136
ny, nu = size (systems[1 ])
132
- fig = Plots. subplot (n= (plotphase?2 : 1 )* ny* nu, nc= nu)
137
+ fig = Plots. plot (layout= ((plotphase?2 : 1 )* ny,nu))
138
+ s2i (i,j) = sub2ind ((nu,(plotphase?2 : 1 )* ny),j,i)
133
139
nw = length (w)
134
140
for (si,s) = enumerate (systems)
135
141
mag, phase = bode (s, w)[1 : 2 ]
@@ -145,8 +151,8 @@ function bodeplot{T<:LTISystem}(systems::Vector{T}, w::AbstractVector; plotphase
145
151
continue
146
152
end
147
153
phasedata = vec (phase[:, i, j])
148
- Plots. plot! (fig[(plotphase?( 2 i - 1 ) : i),j], w, magdata, grid= true , yscale= _PlotScaleFunc, xscale= :log10 , xlabel= xlab, title= " Bode plot from: u($j )" , ylabel= " Magnitude $_PlotScaleStr " , lab= " \$ G_\{ $(si) \}\$ " ; getStyleSys (si,length (systems))... , kwargs... )
149
- plotphase && Plots. plot! (fig[ 2 i,j], w, phasedata, grid= true , xscale= :log10 , ylabel= " Phase (deg)" ,xlabel= " Frequency (rad/s)" ; getStyleSys (si,length (systems))... , kwargs... )
154
+ Plots. plot! (fig, w, magdata, grid= true , yscale= _PlotScaleFunc, xscale= :log10 , xlabel= xlab, subplot = s2i ((plotphase?( 2 i - 1 ) : i),j) , title= " Bode plot from: u($j )" , ylabel= " Magnitude $_PlotScaleStr " , lab= " \$ G_\{ $(si) \}\$ " ; getStyleSys (si,length (systems))... , kwargs... )
155
+ plotphase && Plots. plot! (fig, w, phasedata, grid= true , xscale= :log10 , ylabel= " Phase (deg)" , subplot = s2i ( 2 i,j), xlabel= " Frequency (rad/s)" , lab = " \$ G_ \{ $(si) \}\$ " ; getStyleSys (si,length (systems))... , kwargs... )
150
156
end
151
157
end
152
158
end
@@ -169,7 +175,8 @@ function nyquistplot{T<:LTISystem}(systems::Vector{T}, w::AbstractVector; neg=fa
169
175
end
170
176
ny, nu = size (systems[1 ])
171
177
nw = length (w)
172
- fig = Plots. subplot (n= ny* nu, nc= nu)
178
+ fig = Plots. plot (layout= (ny,nu))
179
+ s2i (i,j) = sub2ind ((ny,nu),j,i)
173
180
# Ensure that `axes` is always a matrix of handles
174
181
for (si,s) = enumerate (systems)
175
182
re_resp, im_resp = nyquist (s, w)[1 : 2 ]
@@ -179,13 +186,13 @@ function nyquistplot{T<:LTISystem}(systems::Vector{T}, w::AbstractVector; neg=fa
179
186
imdata = im_resp[:, i, j]
180
187
ylim = (min (max (- 20 ,minimum (imdata)),- 1 ), max (min (20 ,maximum (imdata)),1 ))
181
188
xlim = (min (max (- 20 ,minimum (redata)),- 1 ), max (min (20 ,maximum (redata)),1 ))
182
- Plots. plot! (fig[i, j], redata, imdata, title= " Nyquist plot from: u($j )" , ylabel= " To: y($i )" , ylims= ylim, xlims= xlim; getStyleSys (si,length (systems))... , kwargs... )
189
+ Plots. plot! (fig, redata, imdata, title= " Nyquist plot from: u($j )" , ylabel= " To: y($i )" , ylims= ylim, xlims= xlim, subplot = s2i (i,j), lab = " \$ G_ \{ $(si) \}\$ " ; getStyleSys (si,length (systems))... , kwargs... )
183
190
184
191
if si == length (systems)
185
192
v = linspace (0 ,2 π,100 )
186
193
S,C = sin (v),cos (v)
187
- Plots. plot! (fig[i, j], C,S,l= :dash ,c= :black , lab= " " )
188
- Plots. plot! (fig[i, j], C- 1 ,S,l= :dash ,c= :red , grid= true , lab= " " )
194
+ Plots. plot! (fig, C,S,l= :dash ,c= :black , lab= " " , subplot = s2i (i,j) )
195
+ Plots. plot! (fig, C- 1 ,S,l= :dash ,c= :red , grid= true , lab= " " , subplot = s2i (i,j) )
189
196
# neg && Plots.plot!(fig[i, j],redata, -imdata, args...)
190
197
end
191
198
end
@@ -381,7 +388,7 @@ function marginplot{T<:LTISystem}(systems::Vector{T}, w::AbstractVector; kwargs.
381
388
end
382
389
ny, nu = size (systems[1 ])
383
390
fig = bodeplot (systems, w, kwargs... )
384
-
391
+ s2i (i,j) = sub2ind ((ny,nu),j,i)
385
392
titles = Array (AbstractString,nu,ny,2 ,2 )
386
393
titles[:,:,1 ,1 ] = " Gm: "
387
394
titles[:,:,2 ,1 ] = " Pm: "
@@ -400,17 +407,17 @@ function marginplot{T<:LTISystem}(systems::Vector{T}, w::AbstractVector; kwargs.
400
407
end
401
408
for k= 1 : length (wgm)
402
409
# Plot gain margins
403
- Plots. plot! (fig[ 2 i - 1 ,j], [wgm[k];wgm[k]], [1 ;mag[k]], lab= " " ; getStyleSys (si,length (systems))... )
410
+ Plots. plot! (fig, [wgm[k];wgm[k]], [1 ;mag[k]], lab= " " , subplot = s2i ( 2 i - 1 ,j) ; getStyleSys (si,length (systems))... )
404
411
end
405
412
# Plot gain line at 1
406
- Plots. plot! (fig[ 2 i - 1 ,j], [w[1 ],w[end ]], [oneLine,oneLine], l= :dash , c= :gray , lab= " " )
413
+ Plots. plot! (fig, [w[1 ],w[end ]], [oneLine,oneLine], l= :dash , c= :gray , lab= " " , subplot = s2i ( 2 i - 1 ,j) )
407
414
titles[j,i,1 ,1 ] *= " [" * join ([@sprintf (" %2.2f" ,v) for v in gm]," , " )* " ] "
408
415
titles[j,i,1 ,2 ] *= " [" * join ([@sprintf (" %2.2f" ,v) for v in wgm]," , " )* " ] "
409
416
for k= 1 : length (wpm)
410
417
# Plot the phase margins
411
- Plots. plot! (fig[ 2 i,j], [wpm[k];wpm[k]],[fullPhase[k];fullPhase[k]- pm[k]], lab= " " ; getStyleSys (si,length (systems))... )
418
+ Plots. plot! (fig, [wpm[k];wpm[k]],[fullPhase[k];fullPhase[k]- pm[k]], lab= " " , subplot = s2i ( 2 i,j) ; getStyleSys (si,length (systems))... )
412
419
# Plot the line at 360*k
413
- Plots. plot! (fig[ 2 i,j], [w[1 ],w[end ]],(fullPhase[k]- pm[k])* ones (2 ), l= :dash , c= :gray , lab= " " )
420
+ Plots. plot! (fig, [w[1 ],w[end ]],(fullPhase[k]- pm[k])* ones (2 ), l= :dash , c= :gray , lab= " " , subplot = s2i ( 2 i,j) )
414
421
end
415
422
titles[j,i,2 ,1 ] *= " [" * join ([@sprintf (" %2.2f" ,v) for v in pm]," , " )* " ] "
416
423
titles[j,i,2 ,2 ] *= " [" * join ([@sprintf (" %2.2f" ,v) for v in wpm]," , " )* " ] "
@@ -419,8 +426,8 @@ function marginplot{T<:LTISystem}(systems::Vector{T}, w::AbstractVector; kwargs.
419
426
end
420
427
for j = 1 : nu
421
428
for i = 1 : ny
422
- Plots. title! (fig[ 2 i - 1 ,j], titles[j,i,1 ,1 ]* " " * titles[j,i,1 ,2 ])
423
- Plots. title! (fig[ 2 i,j], titles[j,i,2 ,1 ]* " " * titles[j,i,2 ,2 ])
429
+ Plots. title! (fig, titles[j,i,1 ,1 ]* " " * titles[j,i,1 ,2 ], subplot = s2i ( 2 i - 1 ,j) )
430
+ Plots. title! (fig, titles[j,i,2 ,1 ]* " " * titles[j,i,2 ,2 ], subplot = s2i ( 2 i,j) )
424
431
end
425
432
end
426
433
return fig
@@ -482,10 +489,11 @@ function gangoffourplot(P::Union{Vector, LTISystem}, C::Vector, args...; plotpha
482
489
S,D,N,T = gangoffour (P,C)
483
490
fig = bodeplot (LTISystem[[S[i] D[i]; N[i] T[i]] for i = 1 : length (C)], args... , plotphase= plotphase; kwargs... )
484
491
lower = plotphase ? 3 : 2
485
- Plots. plot! (fig[1 ,1 ],title= " \$ S = 1/(1+PC)\$ " )
486
- Plots. plot! (fig[1 ,2 ],title= " \$ D = P/(1+PC)\$ " )
487
- Plots. plot! (fig[lower,1 ],title= " \$ N = C/(1+PC)\$ " )
488
- Plots. plot! (fig[lower,2 ],title= " \$ T = PC/(1+PC\$ )" )
492
+ s2i (i,j) = sub2ind ((2 ,(plotphase?4 : 2 )),j,i)
493
+ Plots. plot! (fig,title= " \$ S = 1/(1+PC)\$ " , subplot= s2i (1 ,1 ))
494
+ Plots. plot! (fig,title= " \$ D = P/(1+PC)\$ " , subplot= s2i (1 ,2 ))
495
+ Plots. plot! (fig,title= " \$ N = C/(1+PC)\$ " , subplot= s2i (lower,1 ))
496
+ Plots. plot! (fig,title= " \$ T = PC/(1+PC\$ )" , subplot= s2i (lower,2 ))
489
497
return fig
490
498
end
491
499
0 commit comments