@@ -38,11 +38,25 @@ function setPlotScale(str::AbstractString)
3838 _PlotScale, _PlotScaleFunc, _PlotScaleStr = plotSettings
3939end
4040
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
4256 major_minor_limit = 6
4357 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 ))
4660 major = 10 .^ collect (min: max)
4761 if Plots. backend () != Plots. GRBackend ()
4862 majorText = [latexstring (" \$ 10^{$(round (Int64,i)) }\$ " ) for i = min: max]
@@ -57,7 +71,7 @@ function getLogTicks(x)
5771 minorText = [" $j *10^{$(round (Int64,i)) }" for i = (min- 1 ): (max+ 1 ) for j = 2 : 9 ]
5872 end
5973
60- ind = findall (minimum (x) .<= minor .<= maximum (x) )
74+ ind = findall (minx .<= minor .<= maxx )
6175 minor = minor[ind]
6276 minorText = minorText[ind]
6377 if length (minor) > minor_text_limit
@@ -205,7 +219,7 @@ optionally provided.
205219`kwargs` is sent as argument to Plots.plot."""
206220bodeplot
207221
208- @recipe function bodeplot (p:: Bodeplot ; plotphase= true )
222+ @recipe function bodeplot (p:: Bodeplot ; plotphase= true , ylimsphase = () )
209223 systems = p. args[1 ]
210224 if ! isa (systems, AbstractArray)
211225 systems = typeof (systems)[systems]
@@ -222,7 +236,7 @@ bodeplot
222236 s2i (i,j) = LinearIndices ((nu,(plotphase ? 2 : 1 )* ny))[j,i]
223237 layout --> ((plotphase ? 2 : 1 )* ny,nu)
224238 nw = length (w)
225- xticks --> getLogTicks (w)
239+ xticks --> getLogTicks (w, getlims ( :xlims , plotattributes, w) )
226240
227241 for (si,s) = enumerate (systems)
228242 mag, phase = bode (s, w)[1 : 2 ]
@@ -246,7 +260,7 @@ bodeplot
246260 yscale --> _PlotScaleFunc
247261 xscale --> :log10
248262 if _PlotScale != " dB"
249- yticks --> getLogTicks (magdata)
263+ yticks --> getLogTicks (magdata, getlims ( :ylims , plotattributes, magdata) )
250264 end
251265 xguide --> xlab
252266 yguide --> " Magnitude $_PlotScaleStr "
@@ -260,9 +274,11 @@ bodeplot
260274 if ! plotphase
261275 continue
262276 end
277+
263278 @series begin
264279 grid --> true
265280 xscale --> :log10
281+ ylims := ylimsphase
266282 yguide --> " Phase (deg)"
267283 subplot --> s2i (2 i,j)
268284 xguide --> " Frequency (rad/s)"
287303 yscale --> :log10
288304 xscale --> :log10
289305 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) )
292308 x := w; y := magdata
293309 ()
294310 end
306322 xscale --> :log10
307323 yguide --> " Phase (deg)"
308324 xguide --> " Frequency (rad/s)"
309- xticks --> getLogTicks (w)
325+ xticks --> getLogTicks (w, getlims ( :xlims , plotattributes, w) )
310326 x := w; y := phasedata
311327 ()
312328 end
0 commit comments