diff --git a/RELEASE.rst b/RELEASE.rst index 56e3096d23cb2..9147968997fc7 100644 --- a/RELEASE.rst +++ b/RELEASE.rst @@ -127,6 +127,7 @@ pandas 0.11.1 when ``parse_dates`` is specified (GH3062_) - Fix not consolidating before to_csv (GH3624_) - Fix alignment issue when setitem in a DataFrame with a piece of a DataFrame (GH3626_) + - Fix plotting of unordered DatetimeIndex (GH3601_) .. _GH3164: https://github.com/pydata/pandas/issues/3164 .. _GH2786: https://github.com/pydata/pandas/issues/2786 @@ -180,6 +181,7 @@ pandas 0.11.1 .. _GH3062: https://github.com/pydata/pandas/issues/3062 .. _GH3624: https://github.com/pydata/pandas/issues/3624 .. _GH3626: https://github.com/pydata/pandas/issues/3626 +.. _GH3601: https://github.com/pydata/pandas/issues/3601 .. _GH1512: https://github.com/pydata/pandas/issues/1512 diff --git a/pandas/tests/test_graphics.py b/pandas/tests/test_graphics.py index 5033dc2d3a549..197b26014a760 100644 --- a/pandas/tests/test_graphics.py +++ b/pandas/tests/test_graphics.py @@ -677,7 +677,7 @@ def test_default_color_cycle(self): @slow def test_unordered_ts(self): - df = DataFrame(np.random.randn(3, 1), + df = DataFrame(np.array([3.0, 2.0, 1.0]), index=[date(2012, 10, 1), date(2012, 9, 1), date(2012, 8, 1)], @@ -685,6 +685,8 @@ def test_unordered_ts(self): ax = df.plot() xticks = ax.lines[0].get_xdata() self.assert_(xticks[0] < xticks[1]) + ydata = ax.lines[0].get_ydata() + self.assert_(np.all(ydata == np.array([1.0, 2.0, 3.0]))) class TestDataFrameGroupByPlots(unittest.TestCase): diff --git a/pandas/tools/plotting.py b/pandas/tools/plotting.py index 223e127223195..751f5fcdb82b2 100644 --- a/pandas/tools/plotting.py +++ b/pandas/tools/plotting.py @@ -947,8 +947,8 @@ def _get_xticks(self, convert_period=False): if self.use_index: if convert_period and isinstance(index, PeriodIndex): - index = index.to_timestamp().order() - x = index._mpl_repr() + self.data = self.data.reindex(index=index.order()) + x = self.data.index.to_timestamp()._mpl_repr() elif index.is_numeric(): """ Matplotlib supports numeric values or datetime objects as @@ -958,7 +958,8 @@ def _get_xticks(self, convert_period=False): """ x = index._mpl_repr() elif is_datetype: - x = index.order()._mpl_repr() + self.data = self.data.reindex(index=index.order()) + x = self.data.index._mpl_repr() else: self._need_to_set_index = True x = range(len(index))