33
44
55fig = plt .figure ()
6- x = np .linspace (- np .pi ,np .pi ,100 )
6+ x = np .linspace (- np .pi , np .pi , 100 )
77y = 2 * np .sin (x )
88
9- ax = fig .add_subplot (2 ,2 , 1 )
9+ ax = fig .add_subplot (2 , 2 , 1 )
1010ax .set_title ('centered spines' )
11- ax .plot (x ,y )
11+ ax .plot (x , y )
1212ax .spines ['left' ].set_position ('center' )
1313ax .spines ['right' ].set_color ('none' )
1414ax .spines ['bottom' ].set_position ('center' )
1818ax .xaxis .set_ticks_position ('bottom' )
1919ax .yaxis .set_ticks_position ('left' )
2020
21- ax = fig .add_subplot (2 ,2 , 2 )
21+ ax = fig .add_subplot (2 , 2 , 2 )
2222ax .set_title ('zeroed spines' )
23- ax .plot (x ,y )
23+ ax .plot (x , y )
2424ax .spines ['left' ].set_position ('zero' )
2525ax .spines ['right' ].set_color ('none' )
2626ax .spines ['bottom' ].set_position ('zero' )
3030ax .xaxis .set_ticks_position ('bottom' )
3131ax .yaxis .set_ticks_position ('left' )
3232
33- ax = fig .add_subplot (2 ,2 , 3 )
33+ ax = fig .add_subplot (2 , 2 , 3 )
3434ax .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 ))
3737ax .spines ['right' ].set_color ('none' )
38- ax .spines ['bottom' ].set_position (('axes' ,0.1 ))
38+ ax .spines ['bottom' ].set_position (('axes' , 0.1 ))
3939ax .spines ['top' ].set_color ('none' )
4040ax .spines ['left' ].set_smart_bounds (True )
4141ax .spines ['bottom' ].set_smart_bounds (True )
4242ax .xaxis .set_ticks_position ('bottom' )
4343ax .yaxis .set_ticks_position ('left' )
4444
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 ))
4949ax .spines ['right' ].set_color ('none' )
50- ax .spines ['bottom' ].set_position (('data' ,2 ))
50+ ax .spines ['bottom' ].set_position (('data' , 2 ))
5151ax .spines ['top' ].set_color ('none' )
5252ax .spines ['left' ].set_smart_bounds (True )
5353ax .spines ['bottom' ].set_smart_bounds (True )
5454ax .xaxis .set_ticks_position ('bottom' )
5555ax .yaxis .set_ticks_position ('left' )
5656# ----------------------------------------------------
5757
58- def adjust_spines (ax ,spines ):
58+
59+ def adjust_spines (ax , spines ):
5960 for loc , spine in ax .spines .items ():
6061 if loc in spines :
61- spine .set_position (('outward' ,10 )) # outward by 10 points
62+ spine .set_position (('outward' , 10 )) # outward by 10 points
6263 spine .set_smart_bounds (True )
6364 else :
64- spine .set_color ('none' ) # don't draw spine
65+ spine .set_color ('none' ) # don't draw spine
6566
6667 # turn off ticks where there is no spine
6768 if 'left' in spines :
@@ -78,23 +79,23 @@ def adjust_spines(ax,spines):
7879
7980fig = plt .figure ()
8081
81- x = np .linspace (0 ,2 * np .pi ,100 )
82+ x = np .linspace (0 , 2 * np .pi , 100 )
8283y = 2 * np .sin (x )
8384
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' ])
8788
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 , [])
9192
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' ])
9596
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' ])
99100
100101plt .show ()
0 commit comments