如何使用 Seaborn 在 x 轴上绘制月份,在 y 轴上绘制降雨量?

How to plot Month on the x-axis and Rainfall on the y-axis with Seaborn?

我有一个来自 Kaggle 的一个世纪以来印度月降雨量的数据集:https://www.kaggle.com/ravisane1/monthly-rainfall-data-india-of-a-century。我使用 melt 通过执行 a

将月份从列转换为行
rain_data_by_month = rain_data.melt(id_vars=["State", "District","Year"], 
        var_name="Month", 
        value_name="Rainfall")

现在我想在 X 轴上绘制月份图,在 Y 轴上绘制总降雨量图。所以我先做了一个

rdf = rain_data_by_month.groupby(['Month'])['Rainfall'].sum().reset_index()

如何让 seaborn 以我上面描述的方式绘制 rdf?谢谢!

import pandas as pd
import seaborn as sns
import calendar

# load data
df = pd.read_csv('data/india_monthly_rainfall_data.csv')

# melt
dfm = df.melt(id_vars=["State", "District","Year"],  var_name="Month",  value_name="Rainfall")

# groupby sum
rdf = dfm.groupby(['Month'])['Rainfall'].sum().reset_index()

# ordered
rdf.Month = pd.Categorical(rdf.Month, categories=list(calendar.month_abbr)[1:], ordered=True)

# display(rdf)
Month     Rainfall
  Apr  2.15743e+06
  Aug  1.52092e+07
  Dec  6.44887e+05
  Feb  9.17824e+05
  Jan  7.38981e+05
  Jul  1.65285e+07
  Jun  1.02515e+07
  Mar  1.17930e+06
  May  4.09921e+06
  Nov  1.56662e+06
  Oct  4.33708e+06
  Sep  1.00620e+07

# plot
p = sns.barplot('Month', 'Rainfall', data=rdf)
p.set_ylabel('Rainfall (mm)')
p.set_title(f'1901 - 2002: Total Cumulative Monthly Rainfall')