Skip to content

Fix passing args in groupby plot (GH11805) #11891

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion doc/source/whatsnew/v0.18.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,9 @@ Bug Fixes
- Bug in ``to_numeric`` where it does not raise if input is more than one dimension (:issue:`11776`)

- Bug in parsing timezone offset strings with non-zero minutes (:issue:`11708`)

- Bug in ``df.plot`` using incorrect colors for bar plots under matplotlib 1.5+ (:issue:`11614`)
- Bug in the ``groupby`` ``plot`` method when using keyword arguments (:issue:`11805`).


- Bug in ``.loc`` result with duplicated key may have ``Index`` with incorrect dtype (:issue:`11497`)
- Bug in ``pd.rolling_median`` where memory allocation failed even with sufficient memory (:issue:`11696`)
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ def __init__(self, groupby):
self._groupby = groupby

def __call__(self, *args, **kwargs):
def f(self, *args, **kwargs):
def f(self):
return self.plot(*args, **kwargs)
f.__name__ = 'plot'
return self._groupby.apply(f)
Expand Down
17 changes: 16 additions & 1 deletion pandas/tests/test_graphics.py
Original file line number Diff line number Diff line change
Expand Up @@ -3718,7 +3718,7 @@ def test_plain_axes(self):

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

def test_plot_kwargs(self):

df = DataFrame({'x': [1, 2, 3, 4, 5],
'y': [1, 2, 3, 2, 1],
'z': list('ababa')})

res = df.groupby('z').plot(kind='scatter', x='x', y='y')
# check that a scatter plot is effectively plotted: the axes should
# contain a PathCollection from the scatter plot (GH11805)
self.assertEqual(len(res['a'].collections), 1)

res = df.groupby('z').plot.scatter(x='x', y='y')
self.assertEqual(len(res['a'].collections), 1)


def assert_is_valid_plot_return_object(objs):
import matplotlib.pyplot as plt
if isinstance(objs, np.ndarray):
Expand Down