@@ -38,11 +38,25 @@ function setPlotScale(str::AbstractString)
38
38
_PlotScale, _PlotScaleFunc, _PlotScaleStr = plotSettings
39
39
end
40
40
41
- function getLogTicks (x)
41
+ """
42
+ Get atributes from xlims or ylims
43
+ default to extrema(wmag) if xlims/ylims not defined or empty
44
+ """
45
+ function getlims (xylims, plotattributes, wmag)
46
+ lims = get (plotattributes, xylims, extrema (wmag))
47
+ if lims isa Tuple{<: Number , <: Number } # If x/ylims not supplied as empty
48
+ return lims
49
+ else
50
+ return extrema (wmag)
51
+ end
52
+ end
53
+
54
+ function getLogTicks (x, minmax)
55
+ minx, maxx = minmax
42
56
major_minor_limit = 6
43
57
minor_text_limit = 8
44
- min = ceil (log10 (minimum (x) ))
45
- max = floor (log10 (maximum (x) ))
58
+ min = ceil (log10 (minx ))
59
+ max = floor (log10 (maxx ))
46
60
major = 10 .^ collect (min: max)
47
61
if Plots. backend () != Plots. GRBackend ()
48
62
majorText = [latexstring (" \$ 10^{$(round (Int64,i)) }\$ " ) for i = min: max]
@@ -57,7 +71,7 @@ function getLogTicks(x)
57
71
minorText = [" $j *10^{$(round (Int64,i)) }" for i = (min- 1 ): (max+ 1 ) for j = 2 : 9 ]
58
72
end
59
73
60
- ind = findall (minimum (x) .<= minor .<= maximum (x) )
74
+ ind = findall (minx .<= minor .<= maxx )
61
75
minor = minor[ind]
62
76
minorText = minorText[ind]
63
77
if length (minor) > minor_text_limit
@@ -205,7 +219,7 @@ optionally provided.
205
219
`kwargs` is sent as argument to Plots.plot."""
206
220
bodeplot
207
221
208
- @recipe function bodeplot (p:: Bodeplot ; plotphase= true )
222
+ @recipe function bodeplot (p:: Bodeplot ; plotphase= true , ylimsphase = () )
209
223
systems = p. args[1 ]
210
224
if ! isa (systems, AbstractArray)
211
225
systems = typeof (systems)[systems]
@@ -222,7 +236,7 @@ bodeplot
222
236
s2i (i,j) = LinearIndices ((nu,(plotphase ? 2 : 1 )* ny))[j,i]
223
237
layout --> ((plotphase ? 2 : 1 )* ny,nu)
224
238
nw = length (w)
225
- xticks --> getLogTicks (w)
239
+ xticks --> getLogTicks (w, getlims ( :xlims , plotattributes, w) )
226
240
227
241
for (si,s) = enumerate (systems)
228
242
mag, phase = bode (s, w)[1 : 2 ]
@@ -246,7 +260,7 @@ bodeplot
246
260
yscale --> _PlotScaleFunc
247
261
xscale --> :log10
248
262
if _PlotScale != " dB"
249
- yticks --> getLogTicks (magdata)
263
+ yticks --> getLogTicks (magdata, getlims ( :ylims , plotattributes, magdata) )
250
264
end
251
265
xguide --> xlab
252
266
yguide --> " Magnitude $_PlotScaleStr "
@@ -260,9 +274,11 @@ bodeplot
260
274
if ! plotphase
261
275
continue
262
276
end
277
+
263
278
@series begin
264
279
grid --> true
265
280
xscale --> :log10
281
+ ylims := ylimsphase
266
282
yguide --> " Phase (deg)"
267
283
subplot --> s2i (2 i,j)
268
284
xguide --> " Frequency (rad/s)"
287
303
yscale --> :log10
288
304
xscale --> :log10
289
305
yguide --> " Magnitude"
290
- xticks --> getLogTicks (w)
291
- yticks --> getLogTicks (magdata)
306
+ xticks --> getLogTicks (w, getlims ( :xlims , plotattributes, w) )
307
+ yticks --> getLogTicks (magdata, getlims ( :ylims , plotattributes, magdata) )
292
308
x := w; y := magdata
293
309
()
294
310
end
306
322
xscale --> :log10
307
323
yguide --> " Phase (deg)"
308
324
xguide --> " Frequency (rad/s)"
309
- xticks --> getLogTicks (w)
325
+ xticks --> getLogTicks (w, getlims ( :xlims , plotattributes, w) )
310
326
x := w; y := phasedata
311
327
()
312
328
end
0 commit comments