From 95dc0506f1a9237b0a34a1d26eba1e1a8d357758 Mon Sep 17 00:00:00 2001 From: Tom Augspurger Date: Wed, 13 May 2015 21:53:45 -0500 Subject: [PATCH] BUG: fix Series.plot label setting --- doc/source/whatsnew/v0.17.0.txt | 4 ++++ pandas/tests/test_graphics.py | 23 +++++++++++++++++++++++ pandas/tools/plotting.py | 2 +- 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v0.17.0.txt b/doc/source/whatsnew/v0.17.0.txt index b835733db6f00..f74bd70abb3a8 100644 --- a/doc/source/whatsnew/v0.17.0.txt +++ b/doc/source/whatsnew/v0.17.0.txt @@ -72,3 +72,7 @@ Bug Fixes - Bug in ``DatetimeIndex`` and ``TimedeltaIndex`` names are lost after timedelta arithmetics ( :issue:`9926`) + +- Bug in `Series.plot(label="LABEL")` not correctly setting the label (:issue:`10119`) + + diff --git a/pandas/tests/test_graphics.py b/pandas/tests/test_graphics.py index 33c88b0e3b4b7..4c9d5a9207dd7 100644 --- a/pandas/tests/test_graphics.py +++ b/pandas/tests/test_graphics.py @@ -553,6 +553,29 @@ def test_ts_area_lim(self): self.assertEqual(xmin, line[0]) self.assertEqual(xmax, line[-1]) + def test_label(self): + s = Series([1, 2]) + ax = s.plot(label='LABEL', legend=True) + self._check_legend_labels(ax, labels=['LABEL']) + self.plt.close() + ax = s.plot(legend=True) + self._check_legend_labels(ax, labels=['None']) + self.plt.close() + # get name from index + s.name = 'NAME' + ax = s.plot(legend=True) + self._check_legend_labels(ax, labels=['NAME']) + self.plt.close() + # override the default + ax = s.plot(legend=True, label='LABEL') + self._check_legend_labels(ax, labels=['LABEL']) + self.plt.close() + # Add lebel info, but don't draw + ax = s.plot(legend=False, label='LABEL') + self.assertEqual(ax.get_legend(), None) # Hasn't been drawn + ax.legend() # draw it + self._check_legend_labels(ax, labels=['LABEL']) + def test_line_area_nan_series(self): values = [1, 2, np.nan, 3] s = Series(values) diff --git a/pandas/tools/plotting.py b/pandas/tools/plotting.py index f92f398d9be94..04dd4d3395684 100644 --- a/pandas/tools/plotting.py +++ b/pandas/tools/plotting.py @@ -999,7 +999,7 @@ def _compute_plot_data(self): data = self.data if isinstance(data, Series): - label = self.kwds.pop('label', None) + label = self.label if label is None and data.name is None: label = 'None' data = data.to_frame(name=label)