@@ -1255,43 +1255,40 @@ def _check_bar_alignment(self, df, kind='bar', stacked=False,
12551255 align = align , width = width , position = position ,
12561256 grid = True )
12571257
1258- tick_pos = np .arange (len (df ))
1259-
12601258 axes = self ._flatten_visible (axes )
12611259
12621260 for ax in axes :
12631261 if kind == 'bar' :
12641262 axis = ax .xaxis
12651263 ax_min , ax_max = ax .get_xlim ()
1264+ min_edge = min ([p .get_x () for p in ax .patches ])
1265+ max_edge = max ([p .get_x () + p .get_width () for p in ax .patches ])
12661266 elif kind == 'barh' :
12671267 axis = ax .yaxis
12681268 ax_min , ax_max = ax .get_ylim ()
1269+ min_edge = min ([p .get_y () for p in ax .patches ])
1270+ max_edge = max ([p .get_y () + p .get_height () for p in ax .patches ])
12691271 else :
12701272 raise ValueError
12711273
1274+ # GH 7498
1275+ # compare margins between lim and bar edges
1276+ self .assertAlmostEqual (ax_min , min_edge - 0.25 )
1277+ self .assertAlmostEqual (ax_max , max_edge + 0.25 )
1278+
12721279 p = ax .patches [0 ]
12731280 if kind == 'bar' and (stacked is True or subplots is True ):
12741281 edge = p .get_x ()
12751282 center = edge + p .get_width () * position
1276- tickoffset = width * position
12771283 elif kind == 'bar' and stacked is False :
12781284 center = p .get_x () + p .get_width () * len (df .columns ) * position
12791285 edge = p .get_x ()
1280- if align == 'edge' :
1281- tickoffset = width * (position - 0.5 ) + p .get_width () * 1.5
1282- else :
1283- tickoffset = width * position + p .get_width ()
12841286 elif kind == 'barh' and (stacked is True or subplots is True ):
12851287 center = p .get_y () + p .get_height () * position
12861288 edge = p .get_y ()
1287- tickoffset = width * position
12881289 elif kind == 'barh' and stacked is False :
12891290 center = p .get_y () + p .get_height () * len (df .columns ) * position
12901291 edge = p .get_y ()
1291- if align == 'edge' :
1292- tickoffset = width * (position - 0.5 ) + p .get_height () * 1.5
1293- else :
1294- tickoffset = width * position + p .get_height ()
12951292 else :
12961293 raise ValueError
12971294
@@ -1307,59 +1304,43 @@ def _check_bar_alignment(self, df, kind='bar', stacked=False,
13071304 else :
13081305 raise ValueError
13091306
1310- # Check starting point and axes limit margin
1311- self .assertEqual (ax_min , tick_pos [0 ] - tickoffset - 0.25 )
1312- self .assertEqual (ax_max , tick_pos [- 1 ] - tickoffset + 1 )
1313- # Check tick locations and axes limit margin
1314- t_min = axis .get_ticklocs ()[0 ] - tickoffset
1315- t_max = axis .get_ticklocs ()[- 1 ] - tickoffset
1316- self .assertAlmostEqual (ax_min , t_min - 0.25 )
1317- self .assertAlmostEqual (ax_max , t_max + 1.0 )
13181307 return axes
13191308
13201309 @slow
13211310 def test_bar_stacked_center (self ):
13221311 # GH2157
13231312 df = DataFrame ({'A' : [3 ] * 5 , 'B' : lrange (5 )}, index = lrange (5 ))
1324- axes = self ._check_bar_alignment (df , kind = 'bar' , stacked = True )
1325- # Check the axes has the same drawing range before fixing # GH4525
1326- self .assertEqual (axes [0 ].get_xlim (), (- 0.5 , 4.75 ))
1327-
1313+ self ._check_bar_alignment (df , kind = 'bar' , stacked = True )
13281314 self ._check_bar_alignment (df , kind = 'bar' , stacked = True , width = 0.9 )
1329-
1330- axes = self ._check_bar_alignment (df , kind = 'barh' , stacked = True )
1331- self .assertEqual (axes [0 ].get_ylim (), (- 0.5 , 4.75 ))
1332-
1315+ self ._check_bar_alignment (df , kind = 'barh' , stacked = True )
13331316 self ._check_bar_alignment (df , kind = 'barh' , stacked = True , width = 0.9 )
13341317
13351318 @slow
13361319 def test_bar_center (self ):
13371320 df = DataFrame ({'A' : [3 ] * 5 , 'B' : lrange (5 )}, index = lrange (5 ))
1338- axes = self ._check_bar_alignment (df , kind = 'bar' , stacked = False )
1339- self .assertEqual (axes [0 ].get_xlim (), (- 0.75 , 4.5 ))
1340-
1321+ self ._check_bar_alignment (df , kind = 'bar' , stacked = False )
13411322 self ._check_bar_alignment (df , kind = 'bar' , stacked = False , width = 0.9 )
1342-
1343- axes = self ._check_bar_alignment (df , kind = 'barh' , stacked = False )
1344- self .assertEqual (axes [0 ].get_ylim (), (- 0.75 , 4.5 ))
1345-
1323+ self ._check_bar_alignment (df , kind = 'barh' , stacked = False )
13461324 self ._check_bar_alignment (df , kind = 'barh' , stacked = False , width = 0.9 )
13471325
13481326 @slow
13491327 def test_bar_subplots_center (self ):
13501328 df = DataFrame ({'A' : [3 ] * 5 , 'B' : lrange (5 )}, index = lrange (5 ))
1351- axes = self ._check_bar_alignment (df , kind = 'bar' , subplots = True )
1352- for ax in axes :
1353- self .assertEqual (ax .get_xlim (), (- 0.5 , 4.75 ))
1354-
1329+ self ._check_bar_alignment (df , kind = 'bar' , subplots = True )
13551330 self ._check_bar_alignment (df , kind = 'bar' , subplots = True , width = 0.9 )
1356-
1357- axes = self ._check_bar_alignment (df , kind = 'barh' , subplots = True )
1358- for ax in axes :
1359- self .assertEqual (ax .get_ylim (), (- 0.5 , 4.75 ))
1360-
1331+ self ._check_bar_alignment (df , kind = 'barh' , subplots = True )
13611332 self ._check_bar_alignment (df , kind = 'barh' , subplots = True , width = 0.9 )
13621333
1334+ @slow
1335+ def test_bar_align_single_column (self ):
1336+ df = DataFrame (randn (5 ))
1337+ self ._check_bar_alignment (df , kind = 'bar' , stacked = False )
1338+ self ._check_bar_alignment (df , kind = 'bar' , stacked = True )
1339+ self ._check_bar_alignment (df , kind = 'barh' , stacked = False )
1340+ self ._check_bar_alignment (df , kind = 'barh' , stacked = True )
1341+ self ._check_bar_alignment (df , kind = 'bar' , subplots = True )
1342+ self ._check_bar_alignment (df , kind = 'barh' , subplots = True )
1343+
13631344 @slow
13641345 def test_bar_edge (self ):
13651346 df = DataFrame ({'A' : [3 ] * 5 , 'B' : lrange (5 )}, index = lrange (5 ))
0 commit comments