1
1
2
2
# 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
4
4
# bound ellipses, it demonstrates how significant this error
5
5
# is to our plots.
6
6
14
14
y = 6720.850
15
15
16
16
# 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 )
18
18
19
19
# show some comparative circles
20
20
delta = 6
21
21
22
22
23
23
##################################################
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 )
51
49
52
50
53
51
##################################################
54
52
# 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' )
57
55
58
56
# make the lower-bound ellipse
59
57
diam = (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 )
62
60
63
61
# make the target ellipse
64
62
diam = 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 )
67
65
68
66
# make the upper-bound ellipse
69
67
diam = (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 )
72
70
73
71
# make the target
74
72
diam = 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 )
77
75
78
76
# 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 )
80
78
81
79
##################################################
82
80
# 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' )
85
83
86
84
# make the lower-bound arc
87
85
diam = (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 )
90
88
91
89
# make the target arc
92
90
diam = 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 )
95
93
96
94
# make the upper-bound arc
97
95
diam = (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 )
100
98
101
99
# make the target
102
100
diam = 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 )
105
103
106
104
# 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 )
112
106
113
107
##################################################
114
108
# now lets do the same thing again using a custom ellipse function
115
109
116
-
117
-
118
110
# 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' )
121
113
122
114
# 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" )
124
116
125
117
# 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" )
127
119
128
120
# 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" )
130
122
131
123
# 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" )
133
125
134
126
# 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 )
136
128
137
129
138
130
# 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 )
140
132
141
133
##################################################
142
134
# 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 ):
146
138
147
139
savefig ("ellipse" )
148
140
show ()
149
-
150
-
0 commit comments