更多 catplot() 選項

在 Python 中處理類別資料

Kasey Jones

Research Data Scientist

類別圖的難點

使用 seaborn 建立的計數圖,依使用者洲別與旅客評論類型統計評論次數。

在 Python 中處理類別資料

使用 catplot() 的 FacetGrid

示範用 seaborn 在欄位的不同類別上產生相同視覺化。此圖與前一張含相同資訊,但改為每個使用者洲別各一張圖。

在 Python 中處理類別資料

使用不同引數

sns.catplot(x="Traveler type", kind="count",

col="User continent",
col_wrap=3,
palette=sns.color_palette("Set1"), data=reviews)
  • x"Traveler type"
  • kind"count"
  • col"User continent"
  • col_wrap3
  • palettesns.color_palette("Set1")
  • 常用色盤:"Set""Set2""Tab10""Paired"
1 http://seaborn.pydata.org/tutorial/color_palettes.html
在 Python 中處理類別資料

再看一次

更新配色後的視覺化。每個使用者洲別各有一張計數圖。

在 Python 中處理類別資料

更新圖表

  • 設定:將圖形存為物件:ax
  • 圖標題:ax.fig.suptitle("My title")
  • 座標標籤:ax.set_axis_labels("x-axis-label", "y-axis-label")
  • 標題高度:plt.subplots_adjust(top=.9)
ax = sns.catplot(x="Traveler type", col="User continent", col_wrap=3,
    kind="count", palette=sns.color_palette("Set1"), data=reviews)
ax.fig.suptitle("Hotel Score by Traveler Type & User Continent")
ax.set_axis_labels("Traveler Type", "Number of Reviews")
plt.subplots_adjust(top=.9)
plt.show()
在 Python 中處理類別資料

完成品

本章的最終視覺化,已更新座標標籤與標題。

在 Python 中處理類別資料

catplot() 練習

在 Python 中處理類別資料

Preparing Video For Download...