Skip to content

Commit 354e172

Browse files
committed
BUG:plot.bar misalignment when width=1
1 parent b56cea2 commit 354e172

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

doc/source/whatsnew/v0.18.1.txt

+1
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,7 @@ Bug Fixes
501501
- Bug in ``concat`` raises ``AttributeError`` when input data contains tz-aware datetime and timedelta (:issue:`12620`)
502502
- Bug in ``concat`` doesn't handle empty ``Series`` properly (:issue:`11082`)
503503

504+
- Bug in ``.plot.bar`` alginment when ``width`` is specified with ``int`` (:issue:`12979`)
504505

505506

506507
- Bug in ``fill_value`` is ignored if the argument to a binary operator is a constant (:issue:`12723`)

pandas/tests/test_graphics.py

+20
Original file line numberDiff line numberDiff line change
@@ -2033,6 +2033,26 @@ def test_bar_barwidth_position(self):
20332033
self._check_bar_alignment(df, kind='barh', subplots=True, width=0.9,
20342034
position=0.2)
20352035

2036+
@slow
2037+
def test_bar_barwidth_position_int(self):
2038+
# GH 12979
2039+
df = DataFrame(randn(5, 5))
2040+
2041+
for w in [1, 1.]:
2042+
ax = df.plot.bar(stacked=True, width=w)
2043+
ticks = ax.xaxis.get_ticklocs()
2044+
tm.assert_numpy_array_equal(ticks, np.array([0, 1, 2, 3, 4]))
2045+
self.assertEqual(ax.get_xlim(), (-0.75, 4.75))
2046+
# check left-edge of bars
2047+
self.assertEqual(ax.patches[0].get_x(), -0.5)
2048+
self.assertEqual(ax.patches[-1].get_x(), 3.5)
2049+
2050+
self._check_bar_alignment(df, kind='bar', stacked=True, width=1)
2051+
self._check_bar_alignment(df, kind='barh', stacked=False, width=1)
2052+
self._check_bar_alignment(df, kind='barh', stacked=True, width=1)
2053+
self._check_bar_alignment(df, kind='bar', subplots=True, width=1)
2054+
self._check_bar_alignment(df, kind='barh', subplots=True, width=1)
2055+
20362056
@slow
20372057
def test_bar_bottom_left(self):
20382058
df = DataFrame(rand(5, 5))

pandas/tools/plotting.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# being a bit too dynamic
22
# pylint: disable=E1101
3+
from __future__ import division
4+
35
import warnings
46
import re
57
from math import ceil

0 commit comments

Comments
 (0)