Skip to content

Commit 17c4a95

Browse files
committed
fixed issues identified in review
1 parent 03f87a3 commit 17c4a95

File tree

3 files changed

+81
-43
lines changed

3 files changed

+81
-43
lines changed

control/freqplot.py

Lines changed: 73 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -217,19 +217,19 @@ def bode_plot(syslist, omega=None, dB=None, Hz=None, deg=None,
217217
# If no axes present, create them from scratch
218218
if ax_mag is None or ax_phase is None:
219219
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',
222224
sharex=ax_mag)
223225

224226
# Magnitude plot
225227
if dB:
226228
pltline = ax_mag.semilogx(omega_plot, 20 * np.log10(mag),
227229
*args, **kwargs)
228230
else:
229-
230231
pltline = ax_mag.loglog(omega_plot, mag, *args, **kwargs)
231232

232-
233233
if nyquistfrq_plot:
234234
ax_mag.axvline(nyquistfrq_plot,
235235
color=pltline[0].get_color())
@@ -259,69 +259,96 @@ def bode_plot(syslist, omega=None, dB=None, Hz=None, deg=None,
259259
if Hz:
260260
Wcg, Wcp = Wcg/(2*math.pi),Wcp/(2*math.pi)
261261

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)
263264
ax_phase.axhline(y=phase_limit if deg else math.radians(phase_limit),
264265
color='k', linestyle=':', zorder=-20)
265266
mag_ylim = ax_mag.get_ylim()
266267
phase_ylim = ax_phase.get_ylim()
267268

268269
if pm != float('inf') and Wcp != float('nan'):
269270
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)
271274
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)
273277

274278
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],
278285
color='k', zorder=-20)
279286
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)],
285296
color='k', zorder=-20)
286297

287298
if gm != float('inf') and Wcg != float('nan'):
288299
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)
291304
ax_mag.semilogx([Wcg, Wcg], [0,-20*np.log10(gm)],
292305
color='k', zorder=-20)
293306
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)
296312

297313
if deg:
298314
ax_phase.semilogx([Wcg, Wcg], [1e-8, phase_limit],
299-
color='k', linestyle=':', zorder=-20)
315+
color='k', linestyle=':',
316+
zorder=-20)
300317
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)
303322

304323
ax_mag.set_ylim(mag_ylim)
305324
ax_phase.set_ylim(phase_ylim)
306325

307326
if sisotool:
308-
ax_mag.text(0.04, 0.06, 'G.M.: %.2f %s\nFreq: %.2f %s' %
327+
ax_mag.text(0.04, 0.06,
328+
'G.M.: %.2f %s\nFreq: %.2f %s' %
309329
(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',
312334
transform=ax_mag.transAxes,
313335
fontsize=8 if int(matplotlib.__version__[0]) == 1 else 6)
314-
ax_phase.text(0.04, 0.06, 'P.M.: %.2f %s\nFreq: %.2f %s' %
336+
ax_phase.text(0.04, 0.06,
337+
'P.M.: %.2f %s\nFreq: %.2f %s' %
315338
(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,
319344
fontsize=8 if int(matplotlib.__version__[0]) == 1 else 6)
320345
else:
321346
plt.suptitle('Gm = %.2f %s(at %.2f %s), Pm = %.2f %s (at %.2f %s)' %
322347
(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',
325352
Wcp, 'Hz' if Hz else 'rad/s'))
326353

327354
if nyquistfrq_plot:
@@ -336,12 +363,19 @@ def gen_zero_centered_series(val_min, val_max, period):
336363
return np.arange(v1, v2 + 1) * period
337364
if deg:
338365
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)
341371
else:
342372
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.),
345379
minor=True)
346380
ax_phase.grid(False if margins else True, which='both')
347381
# ax_mag.grid(which='minor', alpha=0.3)
@@ -350,15 +384,17 @@ def gen_zero_centered_series(val_min, val_max, period):
350384
# ax_phase.grid(which='major', alpha=0.9)
351385

352386
# 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)")
354389

355390
if len(syslist) == 1:
356391
return mags[0], phases[0], omegas[0]
357392
else:
358393
return mags, phases, omegas
359394

360395

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):
362398
"""
363399
Nyquist plot for a system
364400

control/sisotool.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77
import matplotlib.pyplot as plt
88
import warnings
99

10-
def sisotool(sys, kvect = None, xlim_rlocus = None, ylim_rlocus = None, plotstr_rlocus = 'b' if int(matplotlib.__version__[0]) == 1 else 'C0',rlocus_grid = False, omega = None, dB = None, Hz = None, deg = None, omega_limits = None, omega_num = None,margins_bode = True, tvect=None):
11-
12-
"""Sisotool
13-
14-
Sisotool style collection of plots inspired by the matlab sisotool.
10+
def sisotool(sys, kvect = None, xlim_rlocus = None, ylim_rlocus = None,
11+
plotstr_rlocus = 'b' if int(matplotlib.__version__[0]) == 1 else 'C0',
12+
rlocus_grid = False, omega = None, dB = None, Hz = None,
13+
deg = None, omega_limits = None, omega_num = None,
14+
margins_bode = True, tvect=None):
15+
"""
16+
Sisotool style collection of plots inspired by MATLAB's sisotool.
1517
The left two plots contain the bode magnitude and phase diagrams.
1618
The top right plot is a clickable root locus plot, clicking on the
1719
root locus will change the gain of the system. The bottom left plot

control/timeresp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ def forced_response(sys, T=None, U=0., X0=0., transpose=False,
375375
def _get_ss_simo(sys, input=None, output=None):
376376
"""Return a SISO or SIMO state-space version of sys
377377
378-
If input is not sfpecified, select first input and issue warning
378+
If input is not specified, select first input and issue warning
379379
"""
380380
sys_ss = _convertToStateSpace(sys)
381381
if sys_ss.issiso():

0 commit comments

Comments
 (0)