3
3
RMM, 31 Mar 2011
4
4
"""
5
5
6
+ import matplotlib .pyplot as plt
7
+
6
8
import pytest
7
9
8
- from control import StateSpace , nichols_plot , nichols
10
+ from control import StateSpace , nichols_plot , nichols , nichols_grid , pade , tf
9
11
10
12
11
13
@pytest .fixture ()
@@ -26,3 +28,73 @@ def test_nichols(tsys, mplcleanup):
26
28
def test_nichols_alias (tsys , mplcleanup ):
27
29
"""Test the control.nichols alias and the grid=False parameter"""
28
30
nichols (tsys , grid = False )
31
+
32
+
33
+ class TestNicholsGrid :
34
+ def test_ax (self ):
35
+ # check grid is plotted into gca, or specified axis
36
+ fig , axs = plt .subplots (2 ,2 )
37
+ plt .sca (axs [0 ,1 ])
38
+
39
+ cl_mag_lines = nichols_grid ()[1 ]
40
+ assert cl_mag_lines [0 ].axes is axs [0 , 1 ]
41
+
42
+ cl_mag_lines = nichols_grid (ax = axs [1 ,1 ])[1 ]
43
+ assert cl_mag_lines [0 ].axes is axs [1 , 1 ]
44
+ # nichols_grid didn't change what the "current axes" are
45
+ assert plt .gca () is axs [0 , 1 ]
46
+
47
+
48
+ def test_cl_phase_label_control (self ):
49
+ # test label_cl_phases argument
50
+ plt .clf ()
51
+ cl_mag_lines , cl_phase_lines , cl_mag_labels , cl_phase_labels \
52
+ = nichols_grid ()
53
+ assert len (cl_phase_labels ) > 0
54
+
55
+ plt .clf ()
56
+ cl_mag_lines , cl_phase_lines , cl_mag_labels , cl_phase_labels \
57
+ = nichols_grid (label_cl_phases = False )
58
+ assert len (cl_phase_labels ) == 0
59
+
60
+
61
+ def test_labels_clipped (self ):
62
+ # regression test: check that contour labels are clipped
63
+ plt .clf ()
64
+ mcontours , ncontours , mlabels , nlabels = nichols_grid ()
65
+ assert all (ml .get_clip_on () for ml in mlabels )
66
+ assert all (nl .get_clip_on () for nl in nlabels )
67
+
68
+
69
+ def test_minimal_phase (self ):
70
+ # regression test: phase extent is minimal
71
+ g = tf ([1 ],[1 ,1 ]) * tf ([1 ],[1 / 1 , 2 * 0.1 / 1 , 1 ])
72
+ plt .clf ()
73
+ nichols (g )
74
+ ax = plt .gca ()
75
+ assert ax .get_xlim ()[1 ] <= 0
76
+
77
+
78
+ def test_fixed_view (self ):
79
+ # respect xlim, ylim set by user
80
+ g = (tf ([1 ],[1 / 1 , 2 * 0.01 / 1 , 1 ])
81
+ * tf ([1 ],[1 / 100 ** 2 , 2 * 0.001 / 100 , 1 ])
82
+ * tf (* pade (0.01 , 5 )))
83
+
84
+ # normally a broad axis
85
+ plt .clf ()
86
+ m , p = nichols (g )
87
+
88
+ assert (plt .xlim ()[0 ] == - 1440 )
89
+ assert (plt .ylim ()[0 ] <= - 240 )
90
+
91
+ plt .clf ()
92
+ nichols (g , grid = False )
93
+
94
+ # zoom in
95
+ plt .axis ([- 360 ,0 ,- 40 ,50 ])
96
+
97
+ # nichols_grid doesn't expand limits
98
+ nichols_grid ()
99
+ assert (plt .xlim ()[0 ] == - 360 )
100
+ assert (plt .ylim ()[1 ] >= - 40 )
0 commit comments