請問matplotlib.pyplot的 plt.bar() and seaborn的sns.barplot()的差異?
在Day 18的作業解答程式碼是用 plt.bar(), 需要先作 age_group分組(如下)。
=======================================
bin_cut = np.linspace(20,70, num=11)
app_train['YEARS_BIRTH_grp'] = pd.cut(app_train['YEARS_BIRTH'],bins=bin_cut)
app_train['YEARS_BIRTH_grp'].value_counts()
age_group = app_train.groupby('YEARS_BIRTH_grp').mean()
age_group.head
plt.figure(figsize=(8,8))
px = range(len(age_group.index))
py = age_group['TARGET']
plt.bar(px, py)
plt.xticks(range(len(age_group.index)), age_group.index, rotation= 75); plt.xlabel('Age group (years)'); plt.ylabel('Failure to Repay (%)')
plt.title('Failure to Repay by Age Group')
========================================
但用 sns.barplot(),不需要先作group分組(如下),一樣可得到相同的圖,請問這樣是不是比較快,還是這二種bar plot 畫法有什麼差異呢?
========================================
import seaborn as sns
plt.style.use('ggplot')
plt.figure(figsize=(8,8))
px = app_train['YEARS_BIRTH_grp']
py = app_train['TARGET']
sns.barplot(px, py)
plt.xticks(rotation = 75); plt.xlabel('Age groups (years)'); plt.ylabel('Failure to Repay (%)')
plt.title('Failure to Repay by Age Group')