@@ -64,15 +64,18 @@ def __call__(self, transform_xy, x1, y1, x2, y2):
64
64
return lon_min , lon_max , lat_min , lat_max
65
65
66
66
67
- def sgrid (ax = None ):
68
- """Draws continuous time damping and frequency grid"""
67
+ def sgrid (fig = None , position = None ):
68
+ """Creates a plot axis with an s-plane (continuous-time) grid
69
+ of constant damping factors and natural frequencies.
70
+ """
69
71
# From matplotlib demos:
70
72
# https://matplotlib.org/gallery/axisartist/demo_curvelinear_grid.html
71
73
# https://matplotlib.org/gallery/axisartist/demo_floating_axis.html
72
74
73
- if ax is None :
74
- ax = plt .gca ()
75
- fig = ax .figure
75
+ if fig is None :
76
+ fig = plt .gcf ()
77
+ if position is None :
78
+ position = (1 , 1 , 1 )
76
79
77
80
# PolarAxes.PolarTransform takes radian. However, we want our coordinate
78
81
# system in degree
@@ -82,19 +85,24 @@ def sgrid(ax=None):
82
85
# (min, max of the coordinate within the view).
83
86
84
87
# 20, 20 : number of sampling points along x, y direction
85
- sampling_points = 20
86
- extreme_finder = ModifiedExtremeFinderCycle (
87
- sampling_points , sampling_points , lon_cycle = 360 , lat_cycle = None ,
88
- lon_minmax = (90 , 270 ), lat_minmax = (0 , np .inf ),)
88
+ n_points = 20
89
+ extreme_finder = ModifiedExtremeFinderCycle (n_points , n_points ,
90
+ lon_cycle = 360 ,
91
+ lat_cycle = None ,
92
+ lon_minmax = (90 ,270 ),
93
+ lat_minmax = (0 , np .inf ))
89
94
90
95
grid_locator1 = angle_helper .LocatorDMS (15 )
91
96
tick_formatter1 = FormatterDMS ()
92
- grid_helper = GridHelperCurveLinear (
93
- tr , extreme_finder = extreme_finder , grid_locator1 = grid_locator1 ,
94
- tick_formatter1 = tick_formatter1 )
97
+ grid_helper = GridHelperCurveLinear (tr ,
98
+ extreme_finder = extreme_finder ,
99
+ grid_locator1 = grid_locator1 ,
100
+ tick_formatter1 = tick_formatter1
101
+ )
95
102
96
- fig = plt .gcf ()
97
- ax = SubplotHost (fig , 1 , 1 , 1 , grid_helper = grid_helper )
103
+ # TODO: Allow positions of type '211', '212' etc.
104
+ ax = SubplotHost (fig , position [0 ], position [1 ], position [2 ],
105
+ grid_helper = grid_helper )
98
106
99
107
# make ticklabels of right invisible, and top axis visible.
100
108
visible = True
@@ -124,27 +132,28 @@ def sgrid(ax=None):
124
132
125
133
fig .add_subplot (ax )
126
134
127
- # RECTANGULAR X Y AXES WITH SCALE
128
- # par2 = ax.twiny()
129
- # par2.axis["top"].toggle(all=False)
130
- # par2.axis["right"].toggle(all=False)
131
- # new_fixed_axis = par2.get_grid_helper().new_fixed_axis
132
- # par2.axis["left"] = new_fixed_axis(loc="left",
135
+ ### RECTANGULAR X Y AXES WITH SCALE
136
+ #par2 = ax.twiny()
137
+ #par2.axis["top"].toggle(all=False)
138
+ #par2.axis["right"].toggle(all=False)
139
+ #new_fixed_axis = par2.get_grid_helper().new_fixed_axis
140
+ #par2.axis["left"] = new_fixed_axis(loc="left",
133
141
# axes=par2,
134
142
# offset=(0, 0))
135
- # par2.axis["bottom"] = new_fixed_axis(loc="bottom",
143
+ #par2.axis["bottom"] = new_fixed_axis(loc="bottom",
136
144
# axes=par2,
137
145
# offset=(0, 0))
138
- # FINISH RECTANGULAR
146
+ ### FINISH RECTANGULAR
139
147
140
- ax .grid (True , zorder = 0 , linestyle = 'dotted' )
148
+ ax .grid (True , zorder = 0 ,linestyle = 'dotted' )
141
149
142
150
_final_setup (ax )
143
151
return ax , fig
144
152
145
153
146
154
def _final_setup (ax , axcolor = 'black' , axlinestyle = '-' ,
147
155
axlinewidth = 1 , equal = True ):
156
+ # Add axes labels and lines through the origin
148
157
ax .set_xlabel ('Real' )
149
158
ax .set_ylabel ('Imaginary' )
150
159
ax .axhline (y = 0 , linestyle = axlinestyle , color = axcolor , lw = axlinewidth ,
@@ -163,12 +172,19 @@ def nogrid(ax=None, axlinestyle='-', axlinewidth=1):
163
172
return ax , fig
164
173
165
174
166
- def zgrid (zetas = None , wns = None , ax = None ):
167
- '''Draws discrete time damping and frequency grid'''
168
-
169
- if ax is None :
170
- ax = plt .gca ()
171
- fig = ax .figure
175
+ def zgrid (zetas = None , wns = None , fig = None , ax = None , position = None ):
176
+ """Creates a plot axis with a z-plane (discrete-time) grid of
177
+ constant damping factors and natural frequencies.
178
+ """
179
+ if fig is None :
180
+ if ax is None :
181
+ ax = plt .gca ()
182
+ fig = ax .figure
183
+ else :
184
+ # Create the axis if only figure is provided
185
+ if position is None :
186
+ position = (1 , 1 , 1 )
187
+ ax = fig .add_subplot (position [0 ], position [1 ], position [2 ])
172
188
173
189
# Constant damping lines
174
190
if zetas is None :
0 commit comments