3
3
4
4
5
5
fig = plt .figure ()
6
- x = np .linspace (- np .pi ,np .pi ,100 )
6
+ x = np .linspace (- np .pi , np .pi , 100 )
7
7
y = 2 * np .sin (x )
8
8
9
- ax = fig .add_subplot (2 ,2 , 1 )
9
+ ax = fig .add_subplot (2 , 2 , 1 )
10
10
ax .set_title ('centered spines' )
11
- ax .plot (x ,y )
11
+ ax .plot (x , y )
12
12
ax .spines ['left' ].set_position ('center' )
13
13
ax .spines ['right' ].set_color ('none' )
14
14
ax .spines ['bottom' ].set_position ('center' )
18
18
ax .xaxis .set_ticks_position ('bottom' )
19
19
ax .yaxis .set_ticks_position ('left' )
20
20
21
- ax = fig .add_subplot (2 ,2 , 2 )
21
+ ax = fig .add_subplot (2 , 2 , 2 )
22
22
ax .set_title ('zeroed spines' )
23
- ax .plot (x ,y )
23
+ ax .plot (x , y )
24
24
ax .spines ['left' ].set_position ('zero' )
25
25
ax .spines ['right' ].set_color ('none' )
26
26
ax .spines ['bottom' ].set_position ('zero' )
30
30
ax .xaxis .set_ticks_position ('bottom' )
31
31
ax .yaxis .set_ticks_position ('left' )
32
32
33
- ax = fig .add_subplot (2 ,2 , 3 )
33
+ ax = fig .add_subplot (2 , 2 , 3 )
34
34
ax .set_title ('spines at axes (0.6, 0.1)' )
35
- ax .plot (x ,y )
36
- ax .spines ['left' ].set_position (('axes' ,0.6 ))
35
+ ax .plot (x , y )
36
+ ax .spines ['left' ].set_position (('axes' , 0.6 ))
37
37
ax .spines ['right' ].set_color ('none' )
38
- ax .spines ['bottom' ].set_position (('axes' ,0.1 ))
38
+ ax .spines ['bottom' ].set_position (('axes' , 0.1 ))
39
39
ax .spines ['top' ].set_color ('none' )
40
40
ax .spines ['left' ].set_smart_bounds (True )
41
41
ax .spines ['bottom' ].set_smart_bounds (True )
42
42
ax .xaxis .set_ticks_position ('bottom' )
43
43
ax .yaxis .set_ticks_position ('left' )
44
44
45
- ax = fig .add_subplot (2 ,2 , 4 )
46
- ax .set_title ('spines at data (1,2)' )
47
- ax .plot (x ,y )
48
- ax .spines ['left' ].set_position (('data' ,1 ))
45
+ ax = fig .add_subplot (2 , 2 , 4 )
46
+ ax .set_title ('spines at data (1, 2)' )
47
+ ax .plot (x , y )
48
+ ax .spines ['left' ].set_position (('data' , 1 ))
49
49
ax .spines ['right' ].set_color ('none' )
50
- ax .spines ['bottom' ].set_position (('data' ,2 ))
50
+ ax .spines ['bottom' ].set_position (('data' , 2 ))
51
51
ax .spines ['top' ].set_color ('none' )
52
52
ax .spines ['left' ].set_smart_bounds (True )
53
53
ax .spines ['bottom' ].set_smart_bounds (True )
54
54
ax .xaxis .set_ticks_position ('bottom' )
55
55
ax .yaxis .set_ticks_position ('left' )
56
56
# ----------------------------------------------------
57
57
58
- def adjust_spines (ax ,spines ):
58
+
59
+ def adjust_spines (ax , spines ):
59
60
for loc , spine in ax .spines .items ():
60
61
if loc in spines :
61
- spine .set_position (('outward' ,10 )) # outward by 10 points
62
+ spine .set_position (('outward' , 10 )) # outward by 10 points
62
63
spine .set_smart_bounds (True )
63
64
else :
64
- spine .set_color ('none' ) # don't draw spine
65
+ spine .set_color ('none' ) # don't draw spine
65
66
66
67
# turn off ticks where there is no spine
67
68
if 'left' in spines :
@@ -78,23 +79,23 @@ def adjust_spines(ax,spines):
78
79
79
80
fig = plt .figure ()
80
81
81
- x = np .linspace (0 ,2 * np .pi ,100 )
82
+ x = np .linspace (0 , 2 * np .pi , 100 )
82
83
y = 2 * np .sin (x )
83
84
84
- ax = fig .add_subplot (2 ,2 , 1 )
85
- ax .plot (x ,y )
86
- adjust_spines (ax ,['left' ])
85
+ ax = fig .add_subplot (2 , 2 , 1 )
86
+ ax .plot (x , y , clip_on = False )
87
+ adjust_spines (ax , ['left' ])
87
88
88
- ax = fig .add_subplot (2 ,2 , 2 )
89
- ax .plot (x ,y )
90
- adjust_spines (ax ,[])
89
+ ax = fig .add_subplot (2 , 2 , 2 )
90
+ ax .plot (x , y , clip_on = False )
91
+ adjust_spines (ax , [])
91
92
92
- ax = fig .add_subplot (2 ,2 , 3 )
93
- ax .plot (x ,y )
94
- adjust_spines (ax ,['left' ,'bottom' ])
93
+ ax = fig .add_subplot (2 , 2 , 3 )
94
+ ax .plot (x , y , clip_on = False )
95
+ adjust_spines (ax , ['left' , 'bottom' ])
95
96
96
- ax = fig .add_subplot (2 ,2 , 4 )
97
- ax .plot (x ,y )
98
- adjust_spines (ax ,['bottom' ])
97
+ ax = fig .add_subplot (2 , 2 , 4 )
98
+ ax .plot (x , y , clip_on = False )
99
+ adjust_spines (ax , ['bottom' ])
99
100
100
101
plt .show ()
0 commit comments