4

I'm not looking for an alternative. I just want to make below code work, because it's a lot simple than otehr solutions.

I want to perform a groupby (A ,B), then scatter plot the relationship for C and D. I want each group is plotted in a subplot. I checked the docs: http://pandas.pydata.org/pandas-docs/version/0.16.2/generated/pandas.core.groupby.DataFrameGroupBy.plot.html It seems to be able to do this in one line. However, the code below plot each group seperately in a new chart.

test = pd.DataFrame({'A': ['foo', 'bar', 'foo', 'bar',
                         'foo', 'bar', 'foo', 'foo'],
                   'B': ['one', 'one', 'two', 'three',
                         'two', 'two', 'one', 'three'],
                   'C': np.random.randn(8),
                   'D': np.random.randn(8)})
test.groupby(['A', 'B']).plot(kind='scatter', x='C', y='D', subplots=True)
plt.show()
5
  • Is this what you want? stackoverflow.com/questions/28293028/… Commented Dec 22, 2017 at 6:21
  • Maybe this one stackoverflow.com/questions/33150510/… ? Commented Dec 22, 2017 at 6:24
  • 1
    @cᴏʟᴅsᴘᴇᴇᴅ This is not what I want. Please open the post again. I want each groupby result plot in a subplot instead of all in one. Commented Dec 22, 2017 at 17:39
  • @Dark my question is more about why the above code does not work as expected, I'm not asking for an alternative. thank you. Commented Dec 22, 2017 at 17:39
  • Please clarify in your post what it is you're trying to solve! Commented Dec 22, 2017 at 18:51

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.