@@ -22,10 +22,10 @@ def _get_cmap_norms():
2222 clevs = [- 5. , - 2.5 , - .5 , .5 , 1.5 , 3.5 ]
2323 # Define norms for the color maps.
2424 norms = dict ()
25- norms ['neither' ] = BoundaryNorm (clevs , len (clevs )- 1 )
26- norms ['min' ] = BoundaryNorm ([- 10 ]+ clevs [1 :], len (clevs )- 1 )
27- norms ['max' ] = BoundaryNorm (clevs [:- 1 ]+ [10 ], len (clevs )- 1 )
28- norms ['both' ] = BoundaryNorm ([- 10 ]+ clevs [1 :- 1 ]+ [10 ], len (clevs )- 1 )
25+ norms ['neither' ] = BoundaryNorm (clevs , len (clevs ) - 1 )
26+ norms ['min' ] = BoundaryNorm ([- 10 ] + clevs [1 :], len (clevs ) - 1 )
27+ norms ['max' ] = BoundaryNorm (clevs [:- 1 ] + [10 ], len (clevs ) - 1 )
28+ norms ['both' ] = BoundaryNorm ([- 10 ] + clevs [1 :- 1 ] + [10 ], len (clevs ) - 1 )
2929 return cmap , norms
3030
3131
@@ -46,7 +46,7 @@ def _colorbar_extension_shape(spacing):
4646 norm = norms [extension_type ]
4747 boundaries = values = norm .boundaries
4848 # Create a subplot.
49- cax = fig .add_subplot (4 , 1 , i + 1 )
49+ cax = fig .add_subplot (4 , 1 , i + 1 )
5050 # Turn off text and ticks.
5151 for item in cax .get_xticklabels () + cax .get_yticklabels () + \
5252 cax .get_xticklines () + cax .get_yticklines ():
@@ -78,7 +78,7 @@ def _colorbar_extension_length(spacing):
7878 boundaries = values = norm .boundaries
7979 for j , extendfrac in enumerate ((None , 'auto' , 0.1 )):
8080 # Create a subplot.
81- cax = fig .add_subplot (12 , 1 , i * 3 + j + 1 )
81+ cax = fig .add_subplot (12 , 1 , i * 3 + j + 1 )
8282 # Turn off text and ticks.
8383 for item in cax .get_xticklabels () + cax .get_yticklabels () + \
8484 cax .get_xticklines () + cax .get_yticklines ():
@@ -128,19 +128,19 @@ def test_colorbar_positioning():
128128 data = np .arange (1200 ).reshape (30 , 40 )
129129 levels = [0 , 200 , 400 , 600 , 800 , 1000 , 1200 ]
130130
131+ # -------------------
131132 plt .figure ()
132133 plt .contourf (data , levels = levels )
133134 plt .colorbar (orientation = 'horizontal' , use_gridspec = False )
134135
135-
136136 locations = ['left' , 'right' , 'top' , 'bottom' ]
137137 plt .figure ()
138138 for i , location in enumerate (locations ):
139- plt .subplot (2 , 2 , i + 1 )
139+ plt .subplot (2 , 2 , i + 1 )
140140 plt .contourf (data , levels = levels )
141141 plt .colorbar (location = location , use_gridspec = False )
142142
143-
143+ # -------------------
144144 plt .figure ()
145145 # make some other data (random integers)
146146 data_2nd = np .array ([[2 , 3 , 2 , 3 ], [1.5 , 2 , 2 , 3 ], [2 , 3 , 3 , 4 ]])
@@ -149,13 +149,16 @@ def test_colorbar_positioning():
149149
150150 color_mappable = plt .contourf (data , levels = levels , extend = 'both' )
151151 # test extend frac here
152- hatch_mappable = plt .contourf (data_2nd , levels = [1 , 2 , 3 ], colors = 'none' , hatches = ['/' , 'o' , '+' ], extend = 'max' )
152+ hatch_mappable = plt .contourf (data_2nd , levels = [1 , 2 , 3 ], colors = 'none' ,
153+ hatches = ['/' , 'o' , '+' ], extend = 'max' )
153154 plt .contour (hatch_mappable , colors = 'black' )
154155
155- plt .colorbar (color_mappable , location = 'left' , label = 'variable 1' , use_gridspec = False )
156- plt .colorbar (hatch_mappable , location = 'right' , label = 'variable 2' , use_gridspec = False )
157-
156+ plt .colorbar (color_mappable , location = 'left' , label = 'variable 1' ,
157+ use_gridspec = False )
158+ plt .colorbar (hatch_mappable , location = 'right' , label = 'variable 2' ,
159+ use_gridspec = False )
158160
161+ # -------------------
159162 plt .figure ()
160163 ax1 = plt .subplot (211 , anchor = 'NE' , aspect = 'equal' )
161164 plt .contourf (data , levels = levels )
@@ -164,9 +167,12 @@ def test_colorbar_positioning():
164167 ax3 = plt .subplot (224 )
165168 plt .contourf (data , levels = levels )
166169
167- plt .colorbar (ax = [ax2 , ax3 , ax1 ], location = 'right' , pad = 0.0 , shrink = 0.5 , panchor = False , use_gridspec = False )
168- plt .colorbar (ax = [ax2 , ax3 , ax1 ], location = 'left' , shrink = 0.5 , panchor = False , use_gridspec = False )
169- plt .colorbar (ax = [ax1 ], location = 'bottom' , panchor = False , anchor = (0.8 , 0.5 ), shrink = 0.6 , use_gridspec = False )
170+ plt .colorbar (ax = [ax2 , ax3 , ax1 ], location = 'right' , pad = 0.0 , shrink = 0.5 ,
171+ panchor = False , use_gridspec = False )
172+ plt .colorbar (ax = [ax2 , ax3 , ax1 ], location = 'left' , shrink = 0.5 ,
173+ panchor = False , use_gridspec = False )
174+ plt .colorbar (ax = [ax1 ], location = 'bottom' , panchor = False ,
175+ anchor = (0.8 , 0.5 ), shrink = 0.6 , use_gridspec = False )
170176
171177
172178@image_comparison (baseline_images = ['cbar_with_subplots_adjust' ],
@@ -188,6 +194,6 @@ def test_gridspec_make_colorbar():
188194 plt .subplots_adjust (top = 0.95 , right = 0.95 , bottom = 0.2 , hspace = 0.25 )
189195
190196
191- if __name__ == '__main__' :
197+ if __name__ == '__main__' :
192198 import nose
193- nose .runmodule (argv = ['-s' ,'--with-doctest' ], exit = False )
199+ nose .runmodule (argv = ['-s' , '--with-doctest' ], exit = False )
0 commit comments