Skip to content

Commit f2f88c6

Browse files
author
Tom Augspurger
committed
Merge pull request #8812 from onesandzeroes/plotlabel
VIS: plot with `use_index=False` shouldn't plot the index name
2 parents 072e40b + 7a8534b commit f2f88c6

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

doc/source/whatsnew/v0.15.2.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,4 @@ Bug Fixes
9393

9494
- Bug in `pd.infer_freq`/`DataFrame.inferred_freq` that prevented proper sub-daily frequency inference
9595
when the index contained DST days (:issue:`8772`).
96+
- Bug where index name was still used when plotting a series with ``use_index=False`` (:issue:`8558`).

pandas/tests/test_graphics.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,16 @@ def test_line_area_nan_series(self):
569569
ax = _check_plot_works(d.plot, kind='area', stacked=False)
570570
self.assert_numpy_array_equal(ax.lines[0].get_ydata(), expected)
571571

572+
def test_line_use_index_false(self):
573+
s = Series([1, 2, 3], index=['a', 'b', 'c'])
574+
s.index.name = 'The Index'
575+
ax = s.plot(use_index=False)
576+
label = ax.get_xlabel()
577+
self.assertEqual(label, '')
578+
ax2 = s.plot(kind='bar', use_index=False)
579+
label2 = ax2.get_xlabel()
580+
self.assertEqual(label2, '')
581+
572582
@slow
573583
def test_bar_log(self):
574584
expected = np.array([1., 10., 100., 1000.])

pandas/tools/plotting.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1685,7 +1685,7 @@ def _post_plot_logic(self):
16851685
self.rot = 30
16861686
format_date_labels(ax, rot=self.rot)
16871687

1688-
if index_name is not None:
1688+
if index_name is not None and self.use_index:
16891689
ax.set_xlabel(index_name)
16901690

16911691

@@ -1874,15 +1874,15 @@ def _post_plot_logic(self):
18741874
ax.set_xticklabels(str_index)
18751875
if not self.log: # GH3254+
18761876
ax.axhline(0, color='k', linestyle='--')
1877-
if name is not None:
1877+
if name is not None and self.use_index:
18781878
ax.set_xlabel(name)
18791879
elif self.kind == 'barh':
18801880
# horizontal bars
18811881
ax.set_ylim((s_edge, e_edge))
18821882
ax.set_yticks(self.tick_pos)
18831883
ax.set_yticklabels(str_index)
18841884
ax.axvline(0, color='k', linestyle='--')
1885-
if name is not None:
1885+
if name is not None and self.use_index:
18861886
ax.set_ylabel(name)
18871887
else:
18881888
raise NotImplementedError(self.kind)

0 commit comments

Comments
 (0)