@@ -1261,43 +1261,40 @@ def _check_bar_alignment(self, df, kind='bar', stacked=False,
12611261 align = align , width = width , position = position ,
12621262 grid = True )
12631263
1264- tick_pos = np .arange (len (df ))
1265-
12661264 axes = self ._flatten_visible (axes )
12671265
12681266 for ax in axes :
12691267 if kind == 'bar' :
12701268 axis = ax .xaxis
12711269 ax_min , ax_max = ax .get_xlim ()
1270+ min_edge = min ([p .get_x () for p in ax .patches ])
1271+ max_edge = max ([p .get_x () + p .get_width () for p in ax .patches ])
12721272 elif kind == 'barh' :
12731273 axis = ax .yaxis
12741274 ax_min , ax_max = ax .get_ylim ()
1275+ min_edge = min ([p .get_y () for p in ax .patches ])
1276+ max_edge = max ([p .get_y () + p .get_height () for p in ax .patches ])
12751277 else :
12761278 raise ValueError
12771279
1280+ # GH 7498
1281+ # compare margins between lim and bar edges
1282+ self .assertAlmostEqual (ax_min , min_edge - 0.25 )
1283+ self .assertAlmostEqual (ax_max , max_edge + 0.25 )
1284+
12781285 p = ax .patches [0 ]
12791286 if kind == 'bar' and (stacked is True or subplots is True ):
12801287 edge = p .get_x ()
12811288 center = edge + p .get_width () * position
1282- tickoffset = width * position
12831289 elif kind == 'bar' and stacked is False :
12841290 center = p .get_x () + p .get_width () * len (df .columns ) * position
12851291 edge = p .get_x ()
1286- if align == 'edge' :
1287- tickoffset = width * (position - 0.5 ) + p .get_width () * 1.5
1288- else :
1289- tickoffset = width * position + p .get_width ()
12901292 elif kind == 'barh' and (stacked is True or subplots is True ):
12911293 center = p .get_y () + p .get_height () * position
12921294 edge = p .get_y ()
1293- tickoffset = width * position
12941295 elif kind == 'barh' and stacked is False :
12951296 center = p .get_y () + p .get_height () * len (df .columns ) * position
12961297 edge = p .get_y ()
1297- if align == 'edge' :
1298- tickoffset = width * (position - 0.5 ) + p .get_height () * 1.5
1299- else :
1300- tickoffset = width * position + p .get_height ()
13011298 else :
13021299 raise ValueError
13031300
@@ -1313,59 +1310,43 @@ def _check_bar_alignment(self, df, kind='bar', stacked=False,
13131310 else :
13141311 raise ValueError
13151312
1316- # Check starting point and axes limit margin
1317- self .assertEqual (ax_min , tick_pos [0 ] - tickoffset - 0.25 )
1318- self .assertEqual (ax_max , tick_pos [- 1 ] - tickoffset + 1 )
1319- # Check tick locations and axes limit margin
1320- t_min = axis .get_ticklocs ()[0 ] - tickoffset
1321- t_max = axis .get_ticklocs ()[- 1 ] - tickoffset
1322- self .assertAlmostEqual (ax_min , t_min - 0.25 )
1323- self .assertAlmostEqual (ax_max , t_max + 1.0 )
13241313 return axes
13251314
13261315 @slow
13271316 def test_bar_stacked_center (self ):
13281317 # GH2157
13291318 df = DataFrame ({'A' : [3 ] * 5 , 'B' : lrange (5 )}, index = lrange (5 ))
1330- axes = self ._check_bar_alignment (df , kind = 'bar' , stacked = True )
1331- # Check the axes has the same drawing range before fixing # GH4525
1332- self .assertEqual (axes [0 ].get_xlim (), (- 0.5 , 4.75 ))
1333-
1319+ self ._check_bar_alignment (df , kind = 'bar' , stacked = True )
13341320 self ._check_bar_alignment (df , kind = 'bar' , stacked = True , width = 0.9 )
1335-
1336- axes = self ._check_bar_alignment (df , kind = 'barh' , stacked = True )
1337- self .assertEqual (axes [0 ].get_ylim (), (- 0.5 , 4.75 ))
1338-
1321+ self ._check_bar_alignment (df , kind = 'barh' , stacked = True )
13391322 self ._check_bar_alignment (df , kind = 'barh' , stacked = True , width = 0.9 )
13401323
13411324 @slow
13421325 def test_bar_center (self ):
13431326 df = DataFrame ({'A' : [3 ] * 5 , 'B' : lrange (5 )}, index = lrange (5 ))
1344- axes = self ._check_bar_alignment (df , kind = 'bar' , stacked = False )
1345- self .assertEqual (axes [0 ].get_xlim (), (- 0.75 , 4.5 ))
1346-
1327+ self ._check_bar_alignment (df , kind = 'bar' , stacked = False )
13471328 self ._check_bar_alignment (df , kind = 'bar' , stacked = False , width = 0.9 )
1348-
1349- axes = self ._check_bar_alignment (df , kind = 'barh' , stacked = False )
1350- self .assertEqual (axes [0 ].get_ylim (), (- 0.75 , 4.5 ))
1351-
1329+ self ._check_bar_alignment (df , kind = 'barh' , stacked = False )
13521330 self ._check_bar_alignment (df , kind = 'barh' , stacked = False , width = 0.9 )
13531331
13541332 @slow
13551333 def test_bar_subplots_center (self ):
13561334 df = DataFrame ({'A' : [3 ] * 5 , 'B' : lrange (5 )}, index = lrange (5 ))
1357- axes = self ._check_bar_alignment (df , kind = 'bar' , subplots = True )
1358- for ax in axes :
1359- self .assertEqual (ax .get_xlim (), (- 0.5 , 4.75 ))
1360-
1335+ self ._check_bar_alignment (df , kind = 'bar' , subplots = True )
13611336 self ._check_bar_alignment (df , kind = 'bar' , subplots = True , width = 0.9 )
1362-
1363- axes = self ._check_bar_alignment (df , kind = 'barh' , subplots = True )
1364- for ax in axes :
1365- self .assertEqual (ax .get_ylim (), (- 0.5 , 4.75 ))
1366-
1337+ self ._check_bar_alignment (df , kind = 'barh' , subplots = True )
13671338 self ._check_bar_alignment (df , kind = 'barh' , subplots = True , width = 0.9 )
13681339
1340+ @slow
1341+ def test_bar_align_single_column (self ):
1342+ df = DataFrame (randn (5 ))
1343+ self ._check_bar_alignment (df , kind = 'bar' , stacked = False )
1344+ self ._check_bar_alignment (df , kind = 'bar' , stacked = True )
1345+ self ._check_bar_alignment (df , kind = 'barh' , stacked = False )
1346+ self ._check_bar_alignment (df , kind = 'barh' , stacked = True )
1347+ self ._check_bar_alignment (df , kind = 'bar' , subplots = True )
1348+ self ._check_bar_alignment (df , kind = 'barh' , subplots = True )
1349+
13691350 @slow
13701351 def test_bar_edge (self ):
13711352 df = DataFrame ({'A' : [3 ] * 5 , 'B' : lrange (5 )}, index = lrange (5 ))
0 commit comments