11
22# This example can be boiled down to a more simplistic example
3- # to show the problem, but bu including the upper and lower
3+ # to show the problem, but including the upper and lower
44# bound ellipses, it demonstrates how significant this error
55# is to our plots.
66
1414y = 6720.850
1515
1616# get is the radius of a circle through this point
17- r = math .sqrt ( x * x + y * y )
17+ r = math .sqrt (x * x + y * y )
1818
1919# show some comparative circles
2020delta = 6
2121
2222
2323##################################################
24- def custom_ellipse ( ax , x , y , major , minor , theta , numpoints = 750 , ** kwargs ):
25- xs = []
26- ys = []
27- incr = 2.0 * math .pi / numpoints
28- incrTheta = 0.0
29- while incrTheta <= (2.0 * math .pi ):
30- a = major * math .cos ( incrTheta )
31- b = minor * math .sin ( incrTheta )
32- l = math .sqrt ( ( a ** 2 ) + ( b ** 2 ) )
33- phi = math .atan2 ( b , a )
34- incrTheta += incr
35-
36- xs .append ( x + ( l * math .cos ( theta + phi ) ) )
37- ys .append ( y + ( l * math .sin ( theta + phi ) ) )
38- # end while
39-
40- incrTheta = 2.0 * math .pi
41- a = major * math .cos ( incrTheta )
42- b = minor * math .sin ( incrTheta )
43- l = sqrt ( ( a ** 2 ) + ( b ** 2 ) )
44- phi = math .atan2 ( b , a )
45- xs .append ( x + ( l * math .cos ( theta + phi ) ) )
46- ys .append ( y + ( l * math .sin ( theta + phi ) ) )
47-
48- ellipseLine = ax .plot ( xs , ys , ** kwargs )
49-
50-
24+ def custom_ellipse (ax , x , y , major , minor , theta , numpoints = 750 , ** kwargs ):
25+ xs = []
26+ ys = []
27+ incr = 2.0 * math .pi / numpoints
28+ incrTheta = 0.0
29+ while incrTheta <= (2.0 * math .pi ):
30+ a = major * math .cos (incrTheta )
31+ b = minor * math .sin (incrTheta )
32+ l = math .sqrt ((a ** 2 ) + (b ** 2 ))
33+ phi = math .atan2 (b , a )
34+ incrTheta += incr
35+
36+ xs .append (x + (l * math .cos (theta + phi )))
37+ ys .append (y + (l * math .sin (theta + phi )))
38+ # end while
39+
40+ incrTheta = 2.0 * math .pi
41+ a = major * math .cos (incrTheta )
42+ b = minor * math .sin (incrTheta )
43+ l = sqrt ((a ** 2 ) + (b ** 2 ))
44+ phi = math .atan2 (b , a )
45+ xs .append (x + (l * math .cos (theta + phi )))
46+ ys .append (y + (l * math .sin (theta + phi )))
47+
48+ ellipseLine = ax .plot (xs , ys , ** kwargs )
5149
5250
5351##################################################
5452# make the axes
55- ax1 = subplot ( 311 , aspect = 'equal' )
56- ax1 .set_aspect ( 'equal' , 'datalim' )
53+ ax1 = subplot (311 , aspect = 'equal' )
54+ ax1 .set_aspect ('equal' , 'datalim' )
5755
5856# make the lower-bound ellipse
5957diam = (r - delta ) * 2.0
60- lower_ellipse = Ellipse ( (0.0 , 0.0 ), diam , diam , 0.0 , fill = False , edgecolor = "darkgreen" )
61- ax1 .add_patch ( lower_ellipse )
58+ lower_ellipse = Ellipse ((0.0 , 0.0 ), diam , diam , 0.0 , fill = False , edgecolor = "darkgreen" )
59+ ax1 .add_patch (lower_ellipse )
6260
6361# make the target ellipse
6462diam = r * 2.0
65- target_ellipse = Ellipse ( (0.0 , 0.0 ), diam , diam , 0.0 , fill = False , edgecolor = "darkred" )
66- ax1 .add_patch ( target_ellipse )
63+ target_ellipse = Ellipse ((0.0 , 0.0 ), diam , diam , 0.0 , fill = False , edgecolor = "darkred" )
64+ ax1 .add_patch (target_ellipse )
6765
6866# make the upper-bound ellipse
6967diam = (r + delta ) * 2.0
70- upper_ellipse = Ellipse ( (0.0 , 0.0 ), diam , diam , 0.0 , fill = False , edgecolor = "darkblue" )
71- ax1 .add_patch ( upper_ellipse )
68+ upper_ellipse = Ellipse ((0.0 , 0.0 ), diam , diam , 0.0 , fill = False , edgecolor = "darkblue" )
69+ ax1 .add_patch (upper_ellipse )
7270
7371# make the target
7472diam = delta * 2.0
75- target = Ellipse ( (x , y ), diam , diam , 0.0 , fill = False , edgecolor = "#DD1208" )
76- ax1 .add_patch ( target )
73+ target = Ellipse ((x , y ), diam , diam , 0.0 , fill = False , edgecolor = "#DD1208" )
74+ ax1 .add_patch (target )
7775
7876# give it a big marker
79- ax1 .plot ( [x ], [y ], marker = 'x' , linestyle = 'None' , mfc = 'red' , mec = 'red' , markersize = 10 )
77+ ax1 .plot ([x ], [y ], marker = 'x' , linestyle = 'None' , mfc = 'red' , mec = 'red' , markersize = 10 )
8078
8179##################################################
8280# make the axes
83- ax = subplot ( 312 , aspect = 'equal' , sharex = ax1 , sharey = ax1 )
84- ax .set_aspect ( 'equal' , 'datalim' )
81+ ax = subplot (312 , aspect = 'equal' , sharex = ax1 , sharey = ax1 )
82+ ax .set_aspect ('equal' , 'datalim' )
8583
8684# make the lower-bound arc
8785diam = (r - delta ) * 2.0
88- lower_arc = Arc ( (0.0 , 0.0 ), diam , diam , 0.0 , fill = False , edgecolor = "darkgreen" )
89- ax .add_patch ( lower_arc )
86+ lower_arc = Arc ((0.0 , 0.0 ), diam , diam , 0.0 , fill = False , edgecolor = "darkgreen" )
87+ ax .add_patch (lower_arc )
9088
9189# make the target arc
9290diam = r * 2.0
93- target_arc = Arc ( (0.0 , 0.0 ), diam , diam , 0.0 , fill = False , edgecolor = "darkred" )
94- ax .add_patch ( target_arc )
91+ target_arc = Arc ((0.0 , 0.0 ), diam , diam , 0.0 , fill = False , edgecolor = "darkred" )
92+ ax .add_patch (target_arc )
9593
9694# make the upper-bound arc
9795diam = (r + delta ) * 2.0
98- upper_arc = Arc ( (0.0 , 0.0 ), diam , diam , 0.0 , fill = False , edgecolor = "darkblue" )
99- ax .add_patch ( upper_arc )
96+ upper_arc = Arc ((0.0 , 0.0 ), diam , diam , 0.0 , fill = False , edgecolor = "darkblue" )
97+ ax .add_patch (upper_arc )
10098
10199# make the target
102100diam = delta * 2.0
103- target = Arc ( (x , y ), diam , diam , 0.0 , fill = False , edgecolor = "#DD1208" )
104- ax .add_patch ( target )
101+ target = Arc ((x , y ), diam , diam , 0.0 , fill = False , edgecolor = "#DD1208" )
102+ ax .add_patch (target )
105103
106104# give it a big marker
107- ax .plot ( [x ], [y ], marker = 'x' , linestyle = 'None' , mfc = 'red' , mec = 'red' , markersize = 10 )
108-
109-
110-
111-
105+ ax .plot ([x ], [y ], marker = 'x' , linestyle = 'None' , mfc = 'red' , mec = 'red' , markersize = 10 )
112106
113107##################################################
114108# now lets do the same thing again using a custom ellipse function
115109
116-
117-
118110# make the axes
119- ax = subplot ( 313 , aspect = 'equal' , sharex = ax1 , sharey = ax1 )
120- ax .set_aspect ( 'equal' , 'datalim' )
111+ ax = subplot (313 , aspect = 'equal' , sharex = ax1 , sharey = ax1 )
112+ ax .set_aspect ('equal' , 'datalim' )
121113
122114# make the lower-bound ellipse
123- custom_ellipse ( ax , 0.0 , 0.0 , r - delta , r - delta , 0.0 , color = "darkgreen" )
115+ custom_ellipse (ax , 0.0 , 0.0 , r - delta , r - delta , 0.0 , color = "darkgreen" )
124116
125117# make the target ellipse
126- custom_ellipse ( ax , 0.0 , 0.0 , r , r , 0.0 , color = "darkred" )
118+ custom_ellipse (ax , 0.0 , 0.0 , r , r , 0.0 , color = "darkred" )
127119
128120# make the upper-bound ellipse
129- custom_ellipse ( ax , 0.0 , 0.0 , r + delta , r + delta , 0.0 , color = "darkblue" )
121+ custom_ellipse (ax , 0.0 , 0.0 , r + delta , r + delta , 0.0 , color = "darkblue" )
130122
131123# make the target
132- custom_ellipse ( ax , x , y , delta , delta , 0.0 , color = "#BB1208" )
124+ custom_ellipse (ax , x , y , delta , delta , 0.0 , color = "#BB1208" )
133125
134126# give it a big marker
135- ax .plot ( [x ], [y ], marker = 'x' , linestyle = 'None' , mfc = 'red' , mec = 'red' , markersize = 10 )
127+ ax .plot ([x ], [y ], marker = 'x' , linestyle = 'None' , mfc = 'red' , mec = 'red' , markersize = 10 )
136128
137129
138130# give it a big marker
139- ax .plot ( [x ], [y ], marker = 'x' , linestyle = 'None' , mfc = 'red' , mec = 'red' , markersize = 10 )
131+ ax .plot ([x ], [y ], marker = 'x' , linestyle = 'None' , mfc = 'red' , mec = 'red' , markersize = 10 )
140132
141133##################################################
142134# lets zoom in to see the area of interest
@@ -146,5 +138,3 @@ def custom_ellipse( ax, x, y, major, minor, theta, numpoints = 750, **kwargs ):
146138
147139savefig ("ellipse" )
148140show ()
149-
150-
0 commit comments