Additional catplot() options

Làm việc với dữ liệu phân loại trong Python

Kasey Jones

Research Data Scientist

Difficulties with categorical plots

A count plot from created using seaborn that counts occurrences of reviews by user continent and traveler review type.

Làm việc với dữ liệu phân loại trong Python

Using the catplot() facetgrid

An example of using seaborn to create the same visualization across different categories of a column. This visualization contains the same information as the previous graphic but now there is one graphic per user continent category.

Làm việc với dữ liệu phân loại trong Python

Using different arguments

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_wrap: 3
  • palette: sns.color_palette("Set1")
  • Common colors: "Set", "Set2", "Tab10", "Paired"
1 http://seaborn.pydata.org/tutorial/color_palettes.html
Làm việc với dữ liệu phân loại trong Python

One more look

An updated visualization from a previous slide that now has a different color scheme.This visualization contains a count plot for each user continent.

Làm việc với dữ liệu phân loại trong Python

Updating plots

  • Setup: save your graphic as an object: ax
  • Plot title: ax.fig.suptitle("My title")
  • Axis labels: ax.set_axis_labels("x-axis-label", "y-axis-label")
  • Title height: 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()
Làm việc với dữ liệu phân loại trong Python

Finished product

Our final visualization for this chapter. It features updated axis labels and an updated title.

Làm việc với dữ liệu phân loại trong Python

catplot() practice

Làm việc với dữ liệu phân loại trong Python

Preparing Video For Download...