@@ -217,19 +217,19 @@ def bode_plot(syslist, omega=None, dB=None, Hz=None, deg=None,
217
217
# If no axes present, create them from scratch
218
218
if ax_mag is None or ax_phase is None :
219
219
plt .clf ()
220
- ax_mag = plt .subplot (211 ,label = 'control-bode-magnitude' )
221
- ax_phase = plt .subplot (212 ,label = 'control-bode-phase' ,
220
+ ax_mag = plt .subplot (211 ,
221
+ label = 'control-bode-magnitude' )
222
+ ax_phase = plt .subplot (212 ,
223
+ label = 'control-bode-phase' ,
222
224
sharex = ax_mag )
223
225
224
226
# Magnitude plot
225
227
if dB :
226
228
pltline = ax_mag .semilogx (omega_plot ,20 * np .log10 (mag ),
227
229
* args ,** kwargs )
228
230
else :
229
-
230
231
pltline = ax_mag .loglog (omega_plot ,mag ,* args ,** kwargs )
231
232
232
-
233
233
if nyquistfrq_plot :
234
234
ax_mag .axvline (nyquistfrq_plot ,
235
235
color = pltline [0 ].get_color ())
@@ -259,69 +259,96 @@ def bode_plot(syslist, omega=None, dB=None, Hz=None, deg=None,
259
259
if Hz :
260
260
Wcg ,Wcp = Wcg / (2 * math .pi ),Wcp / (2 * math .pi )
261
261
262
- ax_mag .axhline (y = 0 if dB else 1 ,color = 'k' ,linestyle = ':' ,zorder = - 20 )
262
+ ax_mag .axhline (y = 0 if dB else 1 ,color = 'k' ,linestyle = ':' ,
263
+ zorder = - 20 )
263
264
ax_phase .axhline (y = phase_limit if deg else math .radians (phase_limit ),
264
265
color = 'k' ,linestyle = ':' ,zorder = - 20 )
265
266
mag_ylim = ax_mag .get_ylim ()
266
267
phase_ylim = ax_phase .get_ylim ()
267
268
268
269
if pm != float ('inf' )and Wcp != float ('nan' ):
269
270
if dB :
270
- ax_mag .semilogx ([Wcp ,Wcp ], [0. ,- 1e5 ],color = 'k' ,linestyle = ':' ,zorder = - 20 )
271
+ ax_mag .semilogx ([Wcp ,Wcp ], [0. ,- 1e5 ],
272
+ color = 'k' ,linestyle = ':' ,
273
+ zorder = - 20 )
271
274
else :
272
- ax_mag .loglog ([Wcp ,Wcp ], [1. ,1e-8 ],color = 'k' ,linestyle = ':' ,zorder = - 20 )
275
+ ax_mag .loglog ([Wcp ,Wcp ], [1. ,1e-8 ],color = 'k' ,
276
+ linestyle = ':' ,zorder = - 20 )
273
277
274
278
if deg :
275
- ax_phase .semilogx ([Wcp ,Wcp ], [1e5 ,phase_limit + pm ],
276
- color = 'k' ,linestyle = ':' ,zorder = - 20 )
277
- ax_phase .semilogx ([Wcp ,Wcp ], [phase_limit + pm ,phase_limit ],
279
+ ax_phase .semilogx ([Wcp ,Wcp ],
280
+ [1e5 ,phase_limit + pm ],
281
+ color = 'k' ,linestyle = ':' ,
282
+ zorder = - 20 )
283
+ ax_phase .semilogx ([Wcp ,Wcp ],
284
+ [phase_limit + pm ,phase_limit ],
278
285
color = 'k' ,zorder = - 20 )
279
286
else :
280
- ax_phase .semilogx ([Wcp ,Wcp ], [1e5 ,math .radians (phase_limit )+
281
- math .radians (pm )],
282
- color = 'k' ,linestyle = ':' ,zorder = - 20 )
283
- ax_phase .semilogx ([Wcp ,Wcp ], [math .radians (phase_limit )+ math .radians (pm ),
284
- math .radians (phase_limit )],
287
+ ax_phase .semilogx ([Wcp ,Wcp ],
288
+ [1e5 ,math .radians (phase_limit )+
289
+ math .radians (pm )],
290
+ color = 'k' ,linestyle = ':' ,
291
+ zorder = - 20 )
292
+ ax_phase .semilogx ([Wcp ,Wcp ],
293
+ [math .radians (phase_limit )+
294
+ math .radians (pm ),
295
+ math .radians (phase_limit )],
285
296
color = 'k' ,zorder = - 20 )
286
297
287
298
if gm != float ('inf' )and Wcg != float ('nan' ):
288
299
if dB :
289
- ax_mag .semilogx ([Wcg ,Wcg ], [- 20. * np .log10 (gm ),- 1e5 ],
290
- color = 'k' ,linestyle = ':' ,zorder = - 20 )
300
+ ax_mag .semilogx ([Wcg ,Wcg ],
301
+ [- 20. * np .log10 (gm ),- 1e5 ],
302
+ color = 'k' ,linestyle = ':' ,
303
+ zorder = - 20 )
291
304
ax_mag .semilogx ([Wcg ,Wcg ], [0 ,- 20 * np .log10 (gm )],
292
305
color = 'k' ,zorder = - 20 )
293
306
else :
294
- ax_mag .loglog ([Wcg ,Wcg ], [1. / gm ,1e-8 ],color = 'k' ,linestyle = ':' ,zorder = - 20 )
295
- ax_mag .loglog ([Wcg ,Wcg ], [1. ,1. / gm ],color = 'k' ,zorder = - 20 )
307
+ ax_mag .loglog ([Wcg ,Wcg ],
308
+ [1. / gm ,1e-8 ],color = 'k' ,
309
+ linestyle = ':' ,zorder = - 20 )
310
+ ax_mag .loglog ([Wcg ,Wcg ],
311
+ [1. ,1. / gm ],color = 'k' ,zorder = - 20 )
296
312
297
313
if deg :
298
314
ax_phase .semilogx ([Wcg ,Wcg ], [1e-8 ,phase_limit ],
299
- color = 'k' ,linestyle = ':' ,zorder = - 20 )
315
+ color = 'k' ,linestyle = ':' ,
316
+ zorder = - 20 )
300
317
else :
301
- ax_phase .semilogx ([Wcg ,Wcg ], [1e-8 ,math .radians (phase_limit )],
302
- color = 'k' ,linestyle = ':' ,zorder = - 20 )
318
+ ax_phase .semilogx ([Wcg ,Wcg ],
319
+ [1e-8 ,math .radians (phase_limit )],
320
+ color = 'k' ,linestyle = ':' ,
321
+ zorder = - 20 )
303
322
304
323
ax_mag .set_ylim (mag_ylim )
305
324
ax_phase .set_ylim (phase_ylim )
306
325
307
326
if sisotool :
308
- ax_mag .text (0.04 ,0.06 ,'G.M.: %.2f %s\n Freq: %.2f %s' %
327
+ ax_mag .text (0.04 ,0.06 ,
328
+ 'G.M.: %.2f %s\n Freq: %.2f %s' %
309
329
(20 * np .log10 (gm )if dB else gm ,
310
- 'dB ' if dB else '' ,Wcg ,'Hz' if Hz else 'rad/s' ),
311
- horizontalalignment = 'left' ,verticalalignment = 'bottom' ,
330
+ 'dB ' if dB else '' ,
331
+ Wcg ,'Hz' if Hz else 'rad/s' ),
332
+ horizontalalignment = 'left' ,
333
+ verticalalignment = 'bottom' ,
312
334
transform = ax_mag .transAxes ,
313
335
fontsize = 8 if int (matplotlib .__version__ [0 ])== 1 else 6 )
314
- ax_phase .text (0.04 ,0.06 ,'P.M.: %.2f %s\n Freq: %.2f %s' %
336
+ ax_phase .text (0.04 ,0.06 ,
337
+ 'P.M.: %.2f %s\n Freq: %.2f %s' %
315
338
(pm if deg else math .radians (pm ),
316
- 'deg' if deg else 'rad' ,Wcp ,'Hz' if Hz else 'rad/s' ),
317
- horizontalalignment = 'left' ,verticalalignment = 'bottom' ,
318
- transform = ax_phase .transAxes ,
339
+ 'deg' if deg else 'rad' ,
340
+ Wcp ,'Hz' if Hz else 'rad/s' ),
341
+ horizontalalignment = 'left' ,
342
+ verticalalignment = 'bottom' ,
343
+ transform = ax_phase .transAxes ,
319
344
fontsize = 8 if int (matplotlib .__version__ [0 ])== 1 else 6 )
320
345
else :
321
346
plt .suptitle ('Gm = %.2f %s(at %.2f %s), Pm = %.2f %s (at %.2f %s)' %
322
347
(20 * np .log10 (gm )if dB else gm ,
323
- 'dB ' if dB else '\b ' ,Wcg ,'Hz' if Hz else 'rad/s' ,
324
- pm if deg else math .radians (pm ),'deg' if deg else 'rad' ,
348
+ 'dB ' if dB else '\b ' ,
349
+ Wcg ,'Hz' if Hz else 'rad/s' ,
350
+ pm if deg else math .radians (pm ),
351
+ 'deg' if deg else 'rad' ,
325
352
Wcp ,'Hz' if Hz else 'rad/s' ))
326
353
327
354
if nyquistfrq_plot :
@@ -336,12 +363,19 @@ def gen_zero_centered_series(val_min, val_max, period):
336
363
return np .arange (v1 ,v2 + 1 )* period
337
364
if deg :
338
365
ylim = ax_phase .get_ylim ()
339
- ax_phase .set_yticks (gen_zero_centered_series (ylim [0 ],ylim [1 ],45. ))
340
- ax_phase .set_yticks (gen_zero_centered_series (ylim [0 ],ylim [1 ],15. ),minor = True )
366
+ ax_phase .set_yticks (gen_zero_centered_series (ylim [0 ],
367
+ ylim [1 ],45. ))
368
+ ax_phase .set_yticks (gen_zero_centered_series (ylim [0 ],
369
+ ylim [1 ],15. ),
370
+ minor = True )
341
371
else :
342
372
ylim = ax_phase .get_ylim ()
343
- ax_phase .set_yticks (gen_zero_centered_series (ylim [0 ],ylim [1 ],math .pi / 4. ))
344
- ax_phase .set_yticks (gen_zero_centered_series (ylim [0 ],ylim [1 ],math .pi / 12. ),
373
+ ax_phase .set_yticks (gen_zero_centered_series (ylim [0 ],
374
+ ylim [1 ],
375
+ math .pi / 4. ))
376
+ ax_phase .set_yticks (gen_zero_centered_series (ylim [0 ],
377
+ ylim [1 ],
378
+ math .pi / 12. ),
345
379
minor = True )
346
380
ax_phase .grid (False if margins else True ,which = 'both' )
347
381
# ax_mag.grid(which='minor', alpha=0.3)
@@ -350,15 +384,17 @@ def gen_zero_centered_series(val_min, val_max, period):
350
384
# ax_phase.grid(which='major', alpha=0.9)
351
385
352
386
# Label the frequency axis
353
- ax_phase .set_xlabel ("Frequency (Hz)" if Hz else "Frequency (rad/sec)" )
387
+ ax_phase .set_xlabel ("Frequency (Hz)" if Hz
388
+ else "Frequency (rad/sec)" )
354
389
355
390
if len (syslist )== 1 :
356
391
return mags [0 ],phases [0 ],omegas [0 ]
357
392
else :
358
393
return mags ,phases ,omegas
359
394
360
395
361
- def nyquist_plot (syslist ,omega = None ,Plot = True ,color = None ,labelFreq = 0 ,* args ,** kwargs ):
396
+ def nyquist_plot (syslist ,omega = None ,Plot = True ,color = None ,
397
+ labelFreq = 0 ,* args ,** kwargs ):
362
398
"""
363
399
Nyquist plot for a system
364
400