88
99import unittest
1010import numpy as np
11+ import control as ctrl
1112from control .statesp import StateSpace
1213from control .matlab import ss , tf , bode
1314from control .exception import slycot_check
@@ -34,6 +35,50 @@ def test_siso(self):
3435 systf = tf (sys )
3536 bode (systf )
3637
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+
3782 def test_doubleint (self ):
3883 # 30 May 2016, RMM: added to replicate typecast bug in freqresp.py
3984 A = np .matrix ('0, 1; 0, 0' );
0 commit comments