diff --git a/doc/source/v0.14.1.txt b/doc/source/v0.14.1.txt index 8ede5f32dded6..9e992573f568d 100644 --- a/doc/source/v0.14.1.txt +++ b/doc/source/v0.14.1.txt @@ -262,6 +262,8 @@ Bug Fixes +- Bug in area plot with tz-aware time series raises ``ValueError`` (:issue:`7471`) + - Bug in non-monotonic ``Index.union`` may preserve ``name`` incorrectly (:issue:`7458`) - Bug in ``DatetimeIndex.intersection`` doesn't preserve timezone (:issue:`4690`) diff --git a/pandas/tests/test_graphics.py b/pandas/tests/test_graphics.py index d19d071833ea7..dfdd37c468a85 100644 --- a/pandas/tests/test_graphics.py +++ b/pandas/tests/test_graphics.py @@ -460,9 +460,33 @@ def test_plot_figsize_and_title(self): def test_ts_area_lim(self): ax = self.ts.plot(kind='area', stacked=False) xmin, xmax = ax.get_xlim() - lines = ax.get_lines() - self.assertEqual(xmin, lines[0].get_data(orig=False)[0][0]) - self.assertEqual(xmax, lines[0].get_data(orig=False)[0][-1]) + line = ax.get_lines()[0].get_data(orig=False)[0] + self.assertEqual(xmin, line[0]) + self.assertEqual(xmax, line[-1]) + tm.close() + + # GH 7471 + ax = self.ts.plot(kind='area', stacked=False, x_compat=True) + xmin, xmax = ax.get_xlim() + line = ax.get_lines()[0].get_data(orig=False)[0] + self.assertEqual(xmin, line[0]) + self.assertEqual(xmax, line[-1]) + tm.close() + + tz_ts = self.ts.copy() + tz_ts.index = tz_ts.tz_localize('GMT').tz_convert('CET') + ax = tz_ts.plot(kind='area', stacked=False, x_compat=True) + xmin, xmax = ax.get_xlim() + line = ax.get_lines()[0].get_data(orig=False)[0] + self.assertEqual(xmin, line[0]) + self.assertEqual(xmax, line[-1]) + tm.close() + + ax = tz_ts.plot(kind='area', stacked=False, secondary_y=True) + xmin, xmax = ax.get_xlim() + line = ax.get_lines()[0].get_data(orig=False)[0] + self.assertEqual(xmin, line[0]) + self.assertEqual(xmax, line[-1]) def test_line_area_nan_series(self): values = [1, 2, np.nan, 3] diff --git a/pandas/tools/plotting.py b/pandas/tools/plotting.py index 2b02523c143b4..7f2f583c5e20e 100644 --- a/pandas/tools/plotting.py +++ b/pandas/tools/plotting.py @@ -1767,7 +1767,9 @@ def _post_plot_logic(self): else: if self.xlim is None: for ax in self.axes: - ax.set_xlim(0, len(self.data)-1) + lines = _get_all_lines(ax) + left, right = _get_xlim(lines) + ax.set_xlim(left, right) if self.ylim is None: if (self.data >= 0).all().all(): @@ -3083,21 +3085,12 @@ def _get_all_lines(ax): def _get_xlim(lines): left, right = np.inf, -np.inf for l in lines: - x = l.get_xdata() - left = min(_maybe_convert_date(x[0]), left) - right = max(_maybe_convert_date(x[-1]), right) + x = l.get_xdata(orig=False) + left = min(x[0], left) + right = max(x[-1], right) return left, right -def _maybe_convert_date(x): - if not com.is_integer(x): - conv_func = conv._dt_to_float_ordinal - if isinstance(x, datetime.time): - conv_func = conv._to_ordinalf - x = conv_func(x) - return x - - if __name__ == '__main__': # import pandas.rpy.common as com # sales = com.load_data('sanfrancisco.home.sales', package='nutshell')