使用 Seaborn 樣式

Seaborn 資料視覺化中級

Chris Moffitt

Instructor

設定樣式

  • Seaborn 有預設設定,可用 sns.set() 套用。
  • 這些樣式也會套用到 matplotlib 與 pandas 的圖形。
sns.set()
df['Tuition'].plot.hist()

直方圖比較

Seaborn 資料視覺化中級

使用 sns.set_style() 的主題範例

for style in ['white','dark','whitegrid','darkgrid','ticks']:
    sns.set_style(style)
    sns.displot(df['Tuition'])
    plt.show()

學費圖

Seaborn 資料視覺化中級

使用 despine() 移除座標軸

  • 有時移除多餘元素能讓圖更清楚。
  • Seaborn 提供快速移除圖框脊線(spines)的方法。
sns.set_style('white')
sns.displot(df['Tuition'])
sns.despine(left=True)

移除脊線範例

Seaborn 資料視覺化中級

一起來練習吧!

Seaborn 資料視覺化中級

Preparing Video For Download...