Skip to content

Commit 7eeeaef

Browse files
committed
BUG: fix Series.plot label setting
1 parent b32f218 commit 7eeeaef

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

doc/source/whatsnew/v0.17.0.txt

+3
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,6 @@ Bug Fixes
6868

6969

7070

71+
- Bug in `Series.plot(label="LABEL")` not correctly setting the label.
72+
73+

pandas/tests/test_graphics.py

+12
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,18 @@ def test_ts_area_lim(self):
553553
self.assertEqual(xmin, line[0])
554554
self.assertEqual(xmax, line[-1])
555555

556+
def test_label(self):
557+
s = Series([1, 2])
558+
ax = s.plot(label='LABEL', legend=True)
559+
self._check_legend_labels(ax, labels=['LABEL'])
560+
self.plt.close()
561+
ax = s.plot(legend=True)
562+
self._check_legend_labels(ax, labels=['None'])
563+
self.plt.close()
564+
s.name = 'NAME'
565+
ax = s.plot(legend=True)
566+
self._check_legend_labels(ax, labels=['NAME'])
567+
556568
def test_line_area_nan_series(self):
557569
values = [1, 2, np.nan, 3]
558570
s = Series(values)

pandas/tools/plotting.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -999,7 +999,7 @@ def _compute_plot_data(self):
999999
data = self.data
10001000

10011001
if isinstance(data, Series):
1002-
label = self.kwds.pop('label', None)
1002+
label = self.label
10031003
if label is None and data.name is None:
10041004
label = 'None'
10051005
data = data.to_frame(name=label)

0 commit comments

Comments
 (0)