15
15
16
16
17
17
def wise (v ):
18
- if v == 1 :
19
- return "CCW"
20
- else :
21
- return "CW"
18
+ return {+ 1 : "CCW" , - 1 : "CW" }[v ]
22
19
23
20
24
21
def make_circle (r ):
25
22
t = np .arange (0 , np .pi * 2.0 , 0.01 )
26
- t = t .reshape ((len (t ), 1 ))
27
23
x = r * np .cos (t )
28
24
y = r * np .sin (t )
29
- return np .hstack ((x , y ))
25
+ return np .column_stack ((x , y ))
30
26
31
- Path = mpath .Path
32
27
33
28
fig , ax = plt .subplots ()
34
29
35
30
inside_vertices = make_circle (0.5 )
36
31
outside_vertices = make_circle (1.0 )
37
- codes = np .ones (
38
- len (inside_vertices ), dtype = mpath .Path .code_type ) * mpath .Path .LINETO
32
+ codes = np .full (len (inside_vertices ), mpath .Path .LINETO )
39
33
codes [0 ] = mpath .Path .MOVETO
40
34
41
35
for i , (inside , outside ) in enumerate (((1 , 1 ), (1 , - 1 ), (- 1 , 1 ), (- 1 , - 1 ))):
@@ -44,23 +38,20 @@ def make_circle(r):
44
38
vertices = np .concatenate ((outside_vertices [::outside ],
45
39
inside_vertices [::inside ]))
46
40
# Shift the path
47
- vertices [:, 0 ] += i * 2.5
41
+ vertices += ( i * 2.5 , 0 )
48
42
# The codes will be all "LINETO" commands, except for "MOVETO"s at the
49
43
# beginning of each subpath
50
44
all_codes = np .concatenate ((codes , codes ))
51
45
# Create the Path object
52
46
path = mpath .Path (vertices , all_codes )
53
- # Add plot it
47
+ # And plot it
54
48
patch = mpatches .PathPatch (path , facecolor = '#885500' , edgecolor = 'black' )
55
49
ax .add_patch (patch )
56
50
57
51
ax .annotate (f"Outside { wise (outside )} ,\n Inside { wise (inside )} " ,
58
52
(i * 2.5 , - 1.5 ), va = "top" , ha = "center" )
59
53
60
- ax .set_xlim (- 2 , 10 )
61
- ax .set_ylim (- 3 , 2 )
62
- ax .set_title ('Mmm, donuts!' )
63
- ax .set_aspect (1.0 )
54
+ ax .set (xlim = (- 2 , 10 ), ylim = (- 3 , 2 ), aspect = 1 , title = "Mmm, donuts!" )
64
55
plt .show ()
65
56
66
57
# %%
0 commit comments