Skip to content

Commit 85faffa

Browse files
committed
add mirror_style keyword for nyquist
1 parent eb62d80 commit 85faffa

2 files changed

Lines changed: 43 additions & 9 deletions

File tree

control/config.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,10 @@ def reset_defaults():
4343
# System level defaults
4444
defaults.update(_control_defaults)
4545

46-
from .freqplot import _bode_defaults, _freqplot_defaults
46+
from .freqplot import _bode_defaults, _freqplot_defaults, _nyquist_defaults
4747
defaults.update(_bode_defaults)
4848
defaults.update(_freqplot_defaults)
49+
defaults.update(_nyquist_defaults)
4950

5051
from .nichols import _nichols_defaults
5152
defaults.update(_nichols_defaults)
@@ -138,9 +139,11 @@ def use_fbs_defaults():
138139
The following conventions are used:
139140
* Bode plots plot gain in powers of ten, phase in degrees,
140141
frequency in rad/sec, no grid
142+
* Nyquist plots use dashed lines for mirror image of Nyquist curve
141143
142144
"""
143145
set_defaults('bode', dB=False, deg=True, Hz=False, grid=False)
146+
set_defaults('nyquist', mirror_style='--')
144147

145148

146149
# Decide whether to use numpy.matrix for state space operations
@@ -239,4 +242,7 @@ def use_legacy_defaults(version):
239242
# time responses are only squeezed if SISO
240243
set_defaults('control', squeeze_time_response=True)
241244

245+
# switched mirror_style of nyquist from '-' to '--'
246+
set_defaults('nyqist', mirror_style='-')
247+
242248
return (major, minor, patch)

control/freqplot.py

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -520,47 +520,69 @@ def gen_zero_centered_series(val_min, val_max, period):
520520
# Nyquist plot
521521
#
522522

523-
def nyquist_plot(
524-
syslist, omega=None, plot=True, omega_limits=None, omega_num=None,
525-
label_freq=0, color=None, mirror='--', arrowhead_length=0.1,
526-
arrowhead_width=0.1, *args, **kwargs):
527-
"""Nyquist plot for a system
523+
# Default values for module parameter variables
524+
_nyquist_defaults = {
525+
'nyquist.mirror_style': '--',
526+
}
527+
528+
def nyquist_plot(syslist, omega=None, plot=True, omega_limits=None,
529+
omega_num=None, label_freq=0, arrowhead_length=0.1,
530+
arrowhead_width=0.1, color=None, *args, **kwargs):
531+
"""
532+
Nyquist plot for a system
528533
529534
Plots a Nyquist plot for the system over a (optional) frequency range.
530535
531536
Parameters
532537
----------
533538
syslist : list of LTI
534539
List of linear input/output systems (single system is OK)
540+
535541
plot : boolean
536542
If True, plot magnitude
543+
537544
omega : array_like
538545
Set of frequencies to be evaluated in rad/sec.
546+
539547
omega_limits : array_like of two values
540548
Limits to the range of frequencies. Ignored if omega
541549
is provided, and auto-generated if omitted.
550+
542551
omega_num : int
543552
Number of samples to plot. Defaults to
544553
config.defaults['freqplot.number_of_samples'].
554+
545555
color : string
546556
Used to specify the color of the line and arrowhead
557+
558+
mirror_style : string or False
559+
Linestyle for mirror image of the Nyquist curve. If `False` then
560+
omit completely. Default linestyle ('--') is determined by
561+
config.defaults['nyquist.mirror_style'].
562+
547563
label_freq : int
548564
Label every nth frequency on the plot
565+
549566
arrowhead_width : float
550567
Arrow head width
568+
551569
arrowhead_length : float
552570
Arrow head length
571+
553572
*args : :func:`matplotlib.pyplot.plot` positional properties, optional
554573
Additional arguments for `matplotlib` plots (color, linestyle, etc)
574+
555575
**kwargs : :func:`matplotlib.pyplot.plot` keyword properties, optional
556576
Additional keywords (passed to `matplotlib`)
557577
558578
Returns
559579
-------
560580
real : ndarray (or list of ndarray if len(syslist) > 1))
561581
real part of the frequency response array
582+
562583
imag : ndarray (or list of ndarray if len(syslist) > 1))
563584
imaginary part of the frequency response array
585+
564586
omega : ndarray (or list of ndarray if len(syslist) > 1))
565587
frequencies in rad/s
566588
@@ -586,6 +608,10 @@ def nyquist_plot(
586608
# Map 'labelFreq' keyword to 'label_freq' keyword
587609
label_freq = kwargs.pop('labelFreq')
588610

611+
# Get values for params (and pop from list to allow keyword use in plot)
612+
mirror_style = config._get_param(
613+
'nyquist', 'mirror_style', kwargs, _nyquist_defaults, pop=True)
614+
589615
# If argument was a singleton, turn it into a list
590616
if not hasattr(syslist, '__iter__'):
591617
syslist = (syslist,)
@@ -634,17 +660,19 @@ def nyquist_plot(
634660
raise ControlMIMONotImplemented(
635661
"Nyquist plot currently supports SISO systems.")
636662

637-
# Plot the primary curve and mirror image
663+
# Plot the primary curve
638664
p = plt.plot(x, y, '-', color=color, *args, **kwargs)
639665
c = p[0].get_color()
640666
ax = plt.gca()
667+
641668
# Plot arrow to indicate Nyquist encirclement orientation
642669
ax.arrow(x[0], y[0], (x[1]-x[0])/2, (y[1]-y[0])/2, fc=c, ec=c,
643670
head_width=arrowhead_width,
644671
head_length=arrowhead_length)
645672

646-
if mirror is not False:
647-
plt.plot(x, -y, mirror, color=c, *args, **kwargs)
673+
# Plot the mirror image
674+
if mirror_style is not False:
675+
plt.plot(x, -y, mirror_style, color=c, *args, **kwargs)
648676
ax.arrow(
649677
x[-1], -y[-1], (x[-1]-x[-2])/2, (y[-1]-y[-2])/2,
650678
fc=c, ec=c, head_width=arrowhead_width,

0 commit comments

Comments
 (0)