@@ -38,11 +38,12 @@ function setPlotScale(str::AbstractString)
38
38
_PlotScale, _PlotScaleFunc, _PlotScaleStr = plotSettings
39
39
end
40
40
41
- function getLogTicks (x)
41
+ function getLogTicks (x, minmax)
42
+ minx, maxx = minmax
42
43
major_minor_limit = 6
43
44
minor_text_limit = 8
44
- min = ceil (log10 (minimum (x) ))
45
- max = floor (log10 (maximum (x) ))
45
+ min = ceil (log10 (minx ))
46
+ max = floor (log10 (maxx ))
46
47
major = 10. ^ collect (min: max)
47
48
if Plots. backend () != Plots. GRBackend ()
48
49
majorText = [latexstring (" \$ 10^{$(round (Int64,i)) }\$ " ) for i = min: max]
@@ -57,7 +58,7 @@ function getLogTicks(x)
57
58
minorText = [" $j *10^{$(round (Int64,i)) }" for i = (min- 1 ): (max+ 1 ) for j = 2 : 9 ]
58
59
end
59
60
60
- ind = find (minimum (x) .<= minor .<= maximum (x) )
61
+ ind = find (minx .<= minor .<= maxx )
61
62
minor = minor[ind]
62
63
minorText = minorText[ind]
63
64
if length (minor) > minor_text_limit
@@ -205,7 +206,7 @@ optionally provided.
205
206
`kwargs` is sent as argument to Plots.plot.""" ->
206
207
bodeplot
207
208
208
- @recipe function bodeplot (p:: Bodeplot ; plotphase= true )
209
+ @recipe function bodeplot (p:: Bodeplot ; plotphase= true , ylimsphase = nothing )
209
210
systems = p. args[1 ]
210
211
if ! isa (systems, AbstractArray)
211
212
systems = [systems]
@@ -222,7 +223,7 @@ bodeplot
222
223
s2i (i,j) = sub2ind ((nu,(plotphase?2 : 1 )* ny),j,i)
223
224
layout := ((plotphase?2 : 1 )* ny,nu)
224
225
nw = length (w)
225
- xticks --> getLogTicks (w)
226
+ xticks --> getLogTicks (w, get (plotattributes, :xlims , ( minimum (w), maximum (w))) )
226
227
227
228
for (si,s) = enumerate (systems)
228
229
mag, phase = bode (s, w)[1 : 2 ]
@@ -246,7 +247,7 @@ bodeplot
246
247
yscale --> _PlotScaleFunc
247
248
xscale --> :log10
248
249
if _PlotScale != " dB"
249
- yticks --> getLogTicks (magdata)
250
+ yticks --> getLogTicks (magdata, get (plotattributes, :ylims , ( minimum (magdata), maximum (magdata))) )
250
251
end
251
252
xguide --> xlab
252
253
yguide --> " Magnitude $_PlotScaleStr "
@@ -260,9 +261,17 @@ bodeplot
260
261
if ! plotphase
261
262
continue
262
263
end
264
+ # Let user specify limits on phase independently
265
+ ylimsphase = if isa (ylimsphase, Void)
266
+ (floor (minimum (phasedata)/ 180 )* 180 ,
267
+ ceil (maximum (phasedata)/ 180 )* 180 )
268
+ else
269
+ ylimsphase
270
+ end
263
271
@series begin
264
272
grid --> true
265
273
xscale --> :log10
274
+ ylims := ylimsphase
266
275
yguide --> " Phase (deg)"
267
276
subplot := s2i (2 i,j)
268
277
xguide --> " Frequency (rad/s)"
287
296
yscale --> :log10
288
297
xscale --> :log10
289
298
yguide --> " Magnitude"
290
- xticks --> getLogTicks (w)
291
- yticks --> getLogTicks (magdata)
299
+ xticks --> getLogTicks (w, get (plotattributes, :xlims , ( minimum (w), maximum (w))) )
300
+ yticks --> getLogTicks (magdata, get (plotattributes, :ylims , ( minimum (magdata), maximum (magdata))) )
292
301
x := w; y := magdata
293
302
()
294
303
end
306
315
xscale --> :log10
307
316
yguide --> " Phase (deg)"
308
317
xguide --> " Frequency (rad/s)"
309
- xticks --> getLogTicks (w)
318
+ xticks --> getLogTicks (w, get (plotattributes, :xlims , ( minimum (w), maximum (w))) )
310
319
x := w; y := phasedata
311
320
()
312
321
end
0 commit comments