Skip to content

Commit 67a17c4

Browse files
Fix passing args in groupby plot (GH11805)
1 parent f295c0a commit 67a17c4

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

doc/source/whatsnew/v0.18.0.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,9 @@ Bug Fixes
330330
- Bug in ``to_numeric`` where it does not raise if input is more than one dimension (:issue:`11776`)
331331

332332
- Bug in parsing timezone offset strings with non-zero minutes (:issue:`11708`)
333-
334333
- Bug in ``df.plot`` using incorrect colors for bar plots under matplotlib 1.5+ (:issue:`11614`)
334+
- Bug in the ``groupby`` ``plot`` method when using keyword arguments (:issue:`11805`).
335+
335336

336337
- Bug in ``.loc`` result with duplicated key may have ``Index`` with incorrect dtype (:issue:`11497`)
337338
- Bug in ``pd.rolling_median`` where memory allocation failed even with sufficient memory (:issue:`11696`)

pandas/core/groupby.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ def __init__(self, groupby):
287287
self._groupby = groupby
288288

289289
def __call__(self, *args, **kwargs):
290-
def f(self, *args, **kwargs):
290+
def f(self):
291291
return self.plot(*args, **kwargs)
292292
f.__name__ = 'plot'
293293
return self._groupby.apply(f)

pandas/tests/test_graphics.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3718,7 +3718,7 @@ def test_plain_axes(self):
37183718

37193719
def test_passed_bar_colors(self):
37203720
import matplotlib as mpl
3721-
color_tuples = [(0.9, 0, 0, 1), (0, 0.9, 0, 1), (0, 0, 0.9, 1)]
3721+
color_tuples = [(0.9, 0, 0, 1), (0, 0.9, 0, 1), (0, 0, 0.9, 1)]
37223722
colormap = mpl.colors.ListedColormap(color_tuples)
37233723
barplot = pd.DataFrame([[1,2,3]]).plot(kind="bar", cmap=colormap)
37243724
self.assertEqual(color_tuples, [c.get_facecolor() for c in barplot.patches])
@@ -3781,6 +3781,21 @@ def test_plot_submethod_works(self):
37813781
df.groupby('z')['x'].plot.line()
37823782
tm.close()
37833783

3784+
def test_plot_kwargs(self):
3785+
3786+
df = DataFrame({'x': [1, 2, 3, 4, 5],
3787+
'y': [1, 2, 3, 2, 1],
3788+
'z': list('ababa')})
3789+
3790+
res = df.groupby('z').plot(kind='scatter', x='x', y='y')
3791+
# check that a scatter plot is effectively plotted: the axes should
3792+
# contain a PathCollection from the scatter plot (GH11805)
3793+
self.assertEqual(len(res['a'].collections), 1)
3794+
3795+
res = df.groupby('z').plot.scatter(x='x', y='y')
3796+
self.assertEqual(len(res['a'].collections), 1)
3797+
3798+
37843799
def assert_is_valid_plot_return_object(objs):
37853800
import matplotlib.pyplot as plt
37863801
if isinstance(objs, np.ndarray):

0 commit comments

Comments
 (0)