8
8
9
9
import unittest
10
10
import numpy as np
11
+ import control as ctrl
11
12
from control .statesp import StateSpace
12
13
from control .matlab import ss , tf , bode
13
14
from control .exception import slycot_check
@@ -34,6 +35,50 @@ def test_siso(self):
34
35
systf = tf (sys )
35
36
bode (systf )
36
37
38
+ def test_superimpose (self ):
39
+ # Test to make sure that multiple calls to plots superimpose their
40
+ # data on the same axes unless told to do otherwise
41
+
42
+ # Generate two plots in a row; should be on the same axes
43
+ plt .figure (1 ); plt .clf ()
44
+ ctrl .bode_plot (ctrl .tf ([1 ], [1 ,2 ,1 ]))
45
+ ctrl .bode_plot (ctrl .tf ([5 ], [1 , 1 ]))
46
+
47
+ # Check to make sure there are two axes and that each axes has two lines
48
+ assert len (plt .gcf ().axes ) == 2
49
+ for ax in plt .gcf ().axes :
50
+ # Make sure there are 2 lines in each subplot
51
+ assert len (ax .get_lines ()) == 2
52
+
53
+ # Generate two plots as a list; should be on the same axes
54
+ plt .figure (2 ); plt .clf ();
55
+ ctrl .bode_plot ([ctrl .tf ([1 ], [1 ,2 ,1 ]), ctrl .tf ([5 ], [1 , 1 ])])
56
+
57
+ # Check to make sure there are two axes and that each axes has two lines
58
+ assert len (plt .gcf ().axes ) == 2
59
+ for ax in plt .gcf ().axes :
60
+ # Make sure there are 2 lines in each subplot
61
+ assert len (ax .get_lines ()) == 2
62
+
63
+ # Generate two separate plots; only the second should appear
64
+ plt .figure (3 ); plt .clf ();
65
+ ctrl .bode_plot (ctrl .tf ([1 ], [1 ,2 ,1 ]))
66
+ plt .clf ()
67
+ ctrl .bode_plot (ctrl .tf ([5 ], [1 , 1 ]))
68
+
69
+ # Check to make sure there are two axes and that each axes has one line
70
+ assert len (plt .gcf ().axes ) == 2
71
+ for ax in plt .gcf ().axes :
72
+ # Make sure there is only 1 line in the subplot
73
+ assert len (ax .get_lines ()) == 1
74
+
75
+ # Now add a line to the magnitude plot and make sure if is there
76
+ for ax in plt .gcf ().axes :
77
+ if ax .get_label () == 'control-bode-magnitude' :
78
+ break
79
+ ax .semilogx ([1e-2 , 1e1 ], 20 * np .log10 ([1 , 1 ]), 'k-' )
80
+ assert len (ax .get_lines ()) == 2
81
+
37
82
def test_doubleint (self ):
38
83
# 30 May 2016, RMM: added to replicate typecast bug in freqresp.py
39
84
A = np .matrix ('0, 1; 0, 0' );
0 commit comments