Skip to content

Commit 38d6909

Browse files
committed
only evaluate interactive code when __main__
1 parent 31cd4d0 commit 38d6909

File tree

1 file changed

+29
-28
lines changed

1 file changed

+29
-28
lines changed

control/tests/nyquist_test.py

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@
1414
import matplotlib.pyplot as plt
1515
import control as ct
1616

17-
# In interactive mode, turn on ipython interactive graphics
18-
plt.ion()
19-
2017

2118
# Utility function for counting unstable poles of open loop (P in FBS)
2219
def _P(sys, indent='right'):
@@ -255,34 +252,38 @@ def test_nyquist_exceptions():
255252
ct.nyquist_plot(sys, np.logspace(-2, 3))
256253

257254

258-
#
259-
# Interactive mode: generate plots for manual viewing
260-
#
261-
# Running this script in python (or better ipython) will show a collection of
262-
# figures that should all look OK on the screeen.
263-
#
255+
if __name__ == "__main__":
256+
#
257+
# Interactive mode: generate plots for manual viewing
258+
#
259+
# Running this script in python (or better ipython) will show a collection of
260+
# figures that should all look OK on the screeen.
261+
#
262+
263+
# In interactive mode, turn on ipython interactive graphics
264+
plt.ion()
264265

265-
# Start by clearing existing figures
266-
plt.close('all')
266+
# Start by clearing existing figures
267+
plt.close('all')
267268

268-
print("Nyquist examples from FBS")
269-
test_nyquist_fbs_examples()
269+
print("Nyquist examples from FBS")
270+
test_nyquist_fbs_examples()
270271

271-
print("Arrow test")
272-
test_nyquist_arrows(None)
273-
test_nyquist_arrows(1)
274-
test_nyquist_arrows(3)
275-
test_nyquist_arrows([0.1, 0.5, 0.9])
272+
print("Arrow test")
273+
test_nyquist_arrows(None)
274+
test_nyquist_arrows(1)
275+
test_nyquist_arrows(3)
276+
test_nyquist_arrows([0.1, 0.5, 0.9])
276277

277-
print("Stability checks")
278-
test_nyquist_encirclements()
278+
print("Stability checks")
279+
test_nyquist_encirclements()
279280

280-
print("Indentation checks")
281-
test_nyquist_indent()
281+
print("Indentation checks")
282+
test_nyquist_indent()
282283

283-
print("Unusual Nyquist plot")
284-
sys = ct.tf([1], [1, 3, 2]) * ct.tf([1], [1, 0, 1])
285-
plt.figure()
286-
plt.title("Poles: %s" % np.array2string(sys.pole(), precision=2, separator=','))
287-
count = ct.nyquist_plot(sys)
288-
assert _Z(sys) == count + _P(sys)
284+
print("Unusual Nyquist plot")
285+
sys = ct.tf([1], [1, 3, 2]) * ct.tf([1], [1, 0, 1])
286+
plt.figure()
287+
plt.title("Poles: %s" % np.array2string(sys.pole(), precision=2, separator=','))
288+
count = ct.nyquist_plot(sys)
289+
assert _Z(sys) == count + _P(sys)

0 commit comments

Comments
 (0)