Skip to content

Commit 22e8bc7

Browse files
committed
BUG: label setting failure in xy plot #2543
1 parent 127651b commit 22e8bc7

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

pandas/tests/test_graphics.py

+9
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,15 @@ def test_plot(self):
221221
index=index)
222222
_check_plot_works(df.plot, title=u'\u03A3')
223223

224+
@slow
225+
def test_label(self):
226+
import matplotlib.pyplot as plt
227+
plt.close('all')
228+
df = DataFrame(np.random.randn(10, 3), columns=['a', 'b', 'c'])
229+
ax = df.plot(x='a', y='b', label='LABEL', legend=True)
230+
self.assert_(ax.get_legend().get_texts()[0].get_text() == 'LABEL')
231+
self.assert_(ax.xaxis.get_label().get_text() == 'LABEL')
232+
224233
@slow
225234
def test_plot_xy(self):
226235
import matplotlib.pyplot as plt

pandas/tools/plotting.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -1414,12 +1414,16 @@ def plot_frame(frame=None, x=None, y=None, subplots=False, sharex=True,
14141414
if y is not None:
14151415
if com.is_integer(y) and not frame.columns.holds_integer():
14161416
y = frame.columns[y]
1417-
return plot_series(frame[y], label=y, kind=kind, use_index=use_index,
1417+
label = kwds.pop('label', y)
1418+
ser = frame[y]
1419+
ser.index.name = label
1420+
return plot_series(ser, label=label, kind=kind,
1421+
use_index=use_index,
14181422
rot=rot, xticks=xticks, yticks=yticks,
14191423
xlim=xlim, ylim=ylim, ax=ax, style=style,
14201424
grid=grid, logy=logy, secondary_y=secondary_y,
14211425
title=title, figsize=figsize, fontsize=fontsize,
1422-
**kwds)
1426+
legend=legend, **kwds)
14231427

14241428
plot_obj = klass(frame, kind=kind, subplots=subplots, rot=rot,
14251429
legend=legend, ax=ax, style=style, fontsize=fontsize,

0 commit comments

Comments
 (0)