1
1
import numpy as np
2
- from numpy import cos , sin , sqrt , linspace , pi , exp
2
+ from numpy import cos , sin , sqrt , pi , exp
3
3
import matplotlib .pyplot as plt
4
4
from mpl_toolkits .axisartist import SubplotHost
5
5
from mpl_toolkits .axisartist .grid_helper_curvelinear \
@@ -19,10 +19,9 @@ def __call__(self, direction, factor, values):
19
19
20
20
21
21
class ModifiedExtremeFinderCycle (angle_helper .ExtremeFinderCycle ):
22
- '''Changed to allow only left hand-side polar grid
23
-
24
- https://matplotlib.org/_modules/mpl_toolkits/axisartist/angle_helper.html#ExtremeFinderCycle.__call__
25
- '''
22
+ # Changed to allow only left hand-side polar grid
23
+ # https://matplotlib.org/_modules/mpl_toolkits/axisartist/angle_helper.html#ExtremeFinderCycle.__call__
24
+
26
25
def __call__ (self , transform_xy , x1 , y1 , x2 , y2 ):
27
26
x , y = np .meshgrid (
28
27
np .linspace (x1 , x2 , self .nx ), np .linspace (y1 , y2 , self .ny ))
@@ -65,11 +64,16 @@ def __call__(self, transform_xy, x1, y1, x2, y2):
65
64
return lon_min , lon_max , lat_min , lat_max
66
65
67
66
68
- def sgrid ():
67
+ def sgrid (ax = None ):
68
+ """Draws continuous time damping and frequency grid"""
69
69
# From matplotlib demos:
70
70
# https://matplotlib.org/gallery/axisartist/demo_curvelinear_grid.html
71
71
# https://matplotlib.org/gallery/axisartist/demo_floating_axis.html
72
72
73
+ if ax is None :
74
+ ax = plt .gca ()
75
+ fig = ax .figure
76
+
73
77
# PolarAxes.PolarTransform takes radian. However, we want our coordinate
74
78
# system in degree
75
79
tr = Affine2D ().scale (np .pi / 180. , 1. ) + PolarAxes .PolarTransform ()
@@ -144,10 +148,11 @@ def _final_setup(ax):
144
148
ax .set_ylabel ('Imaginary' )
145
149
ax .axhline (y = 0 , color = 'black' , lw = 1 )
146
150
ax .axvline (x = 0 , color = 'black' , lw = 1 )
147
- plt .axis ('equal' )
151
+ ax .axis ('equal' )
148
152
149
153
150
154
def nogrid ():
155
+ # TODO: this doesn't look safe. convert to take ax argument
151
156
f = plt .gcf ()
152
157
ax = plt .axes ()
153
158
@@ -156,19 +161,19 @@ def nogrid():
156
161
157
162
158
163
def zgrid (zetas = None , wns = None , ax = None ):
159
- '''Draws discrete damping and frequency grid'''
164
+ '''Draws discrete time damping and frequency grid'''
160
165
161
- fig = plt .gcf ()
162
166
if ax is None :
163
- ax = fig .gca ()
167
+ ax = plt .gca ()
168
+ fig = ax .figure
164
169
165
170
# Constant damping lines
166
171
if zetas is None :
167
- zetas = linspace (0 , 0.9 , 10 )
172
+ zetas = np . linspace (0 , 0.9 , 10 )
168
173
for zeta in zetas :
169
174
# Calculate in polar coordinates
170
175
factor = zeta / sqrt (1 - zeta ** 2 )
171
- x = linspace (0 , sqrt (1 - zeta ** 2 ), 200 )
176
+ x = np . linspace (0 , sqrt (1 - zeta ** 2 ), 200 )
172
177
ang = pi * x
173
178
mag = exp (- pi * factor * x )
174
179
# Draw upper part in retangular coordinates
@@ -188,10 +193,10 @@ def zgrid(zetas=None, wns=None, ax=None):
188
193
189
194
# Constant natural frequency lines
190
195
if wns is None :
191
- wns = linspace (0 , 1 , 10 )
196
+ wns = np . linspace (0 , 1 , 10 )
192
197
for a in wns :
193
198
# Calculate in polar coordinates
194
- x = linspace (- pi / 2 , pi / 2 , 200 )
199
+ x = np . linspace (- pi / 2 , pi / 2 , 200 )
195
200
ang = pi * a * sin (x )
196
201
mag = exp (- pi * a * cos (x ))
197
202
# Draw in retangular coordinates
0 commit comments