2

I wanna make subplots for the following data. I averaged and grouped together. I wanna make subpolts by country for x-axis resource and y-axis average.

country       resource     average
india         water         76
india         soil          45
india         tree          60
US            water         45
US            soil          70
US            tree          85
Germany       water         76
Germany       soil          65
Germany       water         56

Grouped = df.groupby(['country','resource'])['TTR in minutes'].agg({'average': 'mean'}).reset_index()

I tried but couldn't plot in subplots

1 Answer 1

3
g = df.groupby('country')

fig, axes = plt.subplots(g.ngroups, sharex=True, figsize=(8, 6))

for i, (country, d) in enumerate(g):
    ax = d.plot.bar(x='resource', y='average', ax=axes[i], title=country)
    ax.legend().remove()

fig.tight_layout()

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

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.