Skip to content

Commit bf543f7

Browse files
committed
BUG: DataFrame.plot does not respect integer index as x-ticks #2726
1 parent ddbfb3c commit bf543f7

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

pandas/tests/test_graphics.py

+10
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,16 @@ def test_xcompat(self):
300300
lines = ax.get_lines()
301301
self.assert_(isinstance(lines[0].get_xdata(), PeriodIndex))
302302

303+
@slow
304+
def test_unsorted_index(self):
305+
df = DataFrame({'y': range(100)},
306+
index=range(99, -1, -1))
307+
ax = df.plot()
308+
l = ax.get_lines()[0]
309+
rs = l.get_xydata()
310+
rs = Series(rs[:, 1], rs[:, 0], dtype=int)
311+
tm.assert_series_equal(rs, df.y)
312+
303313
def _check_data(self, xp, rs):
304314
xp_lines = xp.get_lines()
305315
rs_lines = rs.get_lines()

pandas/tools/plotting.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -872,13 +872,15 @@ def _get_xticks(self, convert_period=False):
872872
if convert_period and isinstance(index, PeriodIndex):
873873
index = index.to_timestamp().order()
874874
x = index._mpl_repr()
875-
elif index.is_numeric() or is_datetype:
875+
elif index.is_numeric():
876876
"""
877877
Matplotlib supports numeric values or datetime objects as
878878
xaxis values. Taking LBYL approach here, by the time
879879
matplotlib raises exception when using non numeric/datetime
880880
values for xaxis, several actions are already taken by plt.
881881
"""
882+
x = index._mpl_repr()
883+
elif is_datetype:
882884
x = index.order()._mpl_repr()
883885
else:
884886
self._need_to_set_index = True

0 commit comments

Comments
 (0)