I have a group data frame like this :

group_by_region_year_month=train_data.groupby(['Region Name (GO)','Year','Month'],as_index=False)

    region_sum=group_by_region_year_month.agg({"AMV": "sum"})

Here , AMV is my target variable in regression ( this is count of total vehicles).

I have data for each day from 2000-3-17 to 2017-10-11.

I want to show the variation of the count for each year and each month for each Region.

How best can I plot it?

I tried using seaborn.FacetGrid in this way:

# g=sns.FacetGrid(row="Region Name (GO)", col="AMV", data=region_sum)

But it is taking too much time .

Is there any better alternative(s) ?

Edit 1

I tried this :


ax=sns.barplot(x='Region Name (GO)', y='AMV', hue='Year', data=train_data)
ax.set_xticklabels(ax.get_xticklabels(), rotation=90)

which gave me a very clumsy plot : Total vehicle count

I did not use countplot as countplot would give me count of rows. But , I want sum of all values in a group.

Can I represent it in any better way ?


If you like using Seaborn to construct your plots, sns.countplot is probably the best for plotting data where you want to show the differences in value counts.

You can find the link to the documentation page here which might be helpful for you to construct it in the particular way you want.

As an example, here is a version of a "multiple" count plot like you suggest. (directly from the Seaborn Documentation page)

enter image description here

  • $\begingroup$ hi @Ethan , thanks for your reply. Are you suggesting to use multiple countplot. But , I need to show both yearly and monthly data. Would that be possible ? $\endgroup$ – DukeLover Aug 18 '18 at 15:45
  • $\begingroup$ Yes, there is a multiple count plot feature in seaborn. $\endgroup$ – Ethan Aug 18 '18 at 15:46
  • $\begingroup$ hi @Ethan , I updated the question , can u plz check once ? $\endgroup$ – DukeLover Aug 18 '18 at 16:15
  • $\begingroup$ What exactly are you trying to do? If you want to compare value counts for each year (with 17 of them) across each region (with 12 of them) your plot will likely look like the one you have above $\endgroup$ – Ethan Aug 21 '18 at 18:20
  • $\begingroup$ Hi @Ethan , thanks for reply. I want to show as different line plots for various months for 17 regions. $\endgroup$ – DukeLover Aug 22 '18 at 6:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.