Skip to content

BUG:plot.bar misalignment when width=1 #13025

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.18.1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,7 @@ Bug Fixes
- Bug in ``concat`` raises ``AttributeError`` when input data contains tz-aware datetime and timedelta (:issue:`12620`)
- Bug in ``concat`` doesn't handle empty ``Series`` properly (:issue:`11082`)

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


- Bug in ``fill_value`` is ignored if the argument to a binary operator is a constant (:issue:`12723`)
Expand Down
20 changes: 20 additions & 0 deletions pandas/tests/test_graphics.py
Original file line number Diff line number Diff line change
Expand Up @@ -2033,6 +2033,26 @@ def test_bar_barwidth_position(self):
self._check_bar_alignment(df, kind='barh', subplots=True, width=0.9,
position=0.2)

@slow
def test_bar_barwidth_position_int(self):
# GH 12979
df = DataFrame(randn(5, 5))

for w in [1, 1.]:
ax = df.plot.bar(stacked=True, width=w)
ticks = ax.xaxis.get_ticklocs()
tm.assert_numpy_array_equal(ticks, np.array([0, 1, 2, 3, 4]))
self.assertEqual(ax.get_xlim(), (-0.75, 4.75))
# check left-edge of bars
self.assertEqual(ax.patches[0].get_x(), -0.5)
self.assertEqual(ax.patches[-1].get_x(), 3.5)

self._check_bar_alignment(df, kind='bar', stacked=True, width=1)
self._check_bar_alignment(df, kind='barh', stacked=False, width=1)
self._check_bar_alignment(df, kind='barh', stacked=True, width=1)
self._check_bar_alignment(df, kind='bar', subplots=True, width=1)
self._check_bar_alignment(df, kind='barh', subplots=True, width=1)

@slow
def test_bar_bottom_left(self):
df = DataFrame(rand(5, 5))
Expand Down
2 changes: 2 additions & 0 deletions pandas/tools/plotting.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# being a bit too dynamic
# pylint: disable=E1101
from __future__ import division

import warnings
import re
from math import ceil
Expand Down