Skip to content

Commit

Permalink
BUG: Fixed plot label shows as None. pandas-dev#8905
Browse files Browse the repository at this point in the history
  • Loading branch information
dxe4 committed Dec 6, 2014
1 parent 7bd1b24 commit 59ca005
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.15.2.txt
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ Bug Fixes
- Bug in ``merge`` where ``how='left'`` and ``sort=False`` would not preserve left frame order (:issue:`7331`)

- Fix negative step support for label-based slices (:issue:`8753`)
- Fixed given label showing as None (:issue:`#8905`)

Old behavior:

Expand Down
6 changes: 4 additions & 2 deletions pandas/tools/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -1589,7 +1589,9 @@ def _make_plot(self):
errors = self._get_errorbars(label=label, index=i)
kwds = dict(kwds, **errors)

label = com.pprint_thing(label) # .encode('utf-8')
if label is not None or self.legend:
label = com.pprint_thing(label) # .encode('utf-8')

kwds['label'] = label

newlines = plotf(ax, x, y, style=style, column_num=i, **kwds)
Expand Down Expand Up @@ -2283,7 +2285,7 @@ def _plot(data, x=None, y=None, subplots=False,
if com.is_integer(y) and not data.columns.holds_integer():
y = data.columns[y]
label = x if x is not None else data.index.name
label = kwds.pop('label', label)
label = kwds.get('label', label)
series = data[y].copy() # Don't modify
series.index.name = label

Expand Down
14 changes: 14 additions & 0 deletions pandas/tseries/tests/test_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,20 @@ def test_nonnumeric_exclude(self):

self.assertRaises(TypeError, df['A'].plot)

@slow
def test_legend_added(self):
df = DataFrame(np.random.rand(2, 4), columns=['a', 'b', 'c', 'd'])
a_plot = df.plot(kind='scatter', x='a', y='b',
color='DarkBlue', label='Label')
b_plot = df.plot(kind='line', x='a', y='b',
color='DarkBlue', label="foo")
c_plot = df.plot(kind='line', x='a', y='b',
color='DarkBlue', label=None, legend=False)

self.assertEqual(a_plot.legend().texts[0].get_text(), 'Label')
self.assertEqual(b_plot.legend().texts[0].get_text(), 'foo')
self.assertEqual(c_plot.legend(), None)

@slow
def test_tsplot(self):
from pandas.tseries.plotting import tsplot
Expand Down

0 comments on commit 59ca005

Please sign in to comment.