Skip to content

Commit a134eb6

Browse files
committed
Merge pull request #6210 from TomAugspurger/bar-use_index
BUG: dont ignore use_index kw in bar plot
2 parents 1e9f447 + cd33d5b commit a134eb6

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

doc/source/release.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ Bug Fixes
179179
specificed column spec (:issue:`6169`)
180180
- Bug in ``nanops.var`` with ``ddof=1`` and 1 elements would sometimes return ``inf``
181181
rather than ``nan`` on some platforms (:issue:`6136`)
182+
- Bug in Series and DataFrame bar plots ignoring the ``use_index`` keyword (:issue:`6209`)
182183

183184
pandas 0.13.0
184185
-------------

pandas/tests/test_graphics.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,14 @@ def test_bar_log(self):
162162
ax = Series([200, 500]).plot(log=True, kind='bar')
163163
assert_array_equal(ax.yaxis.get_ticklocs(), expected)
164164

165+
@slow
166+
def test_bar_ignore_index(self):
167+
df = Series([1, 2, 3, 4], index=['a', 'b', 'c', 'd'])
168+
ax = df.plot(kind='bar', use_index=False)
169+
expected = ['0', '1', '2', '3']
170+
result = [x.get_text() for x in ax.get_xticklabels()]
171+
self.assertEqual(result, expected)
172+
165173
def test_rotation(self):
166174
df = DataFrame(randn(5, 5))
167175
ax = df.plot(rot=30)

pandas/tools/plotting.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1572,8 +1572,11 @@ def _make_plot(self):
15721572

15731573
def _post_plot_logic(self):
15741574
for ax in self.axes:
1575-
str_index = [com.pprint_thing(key) for key in self.data.index]
1576-
1575+
if self.use_index:
1576+
str_index = [com.pprint_thing(key) for key in self.data.index]
1577+
else:
1578+
str_index = [com.pprint_thing(key) for key in
1579+
range(self.data.shape[0])]
15771580
name = self._get_index_name()
15781581
if self.kind == 'bar':
15791582
ax.set_xlim([self.ax_pos[0] - 0.25, self.ax_pos[-1] + 1])

0 commit comments

Comments
 (0)