Additional catplot() options

Working with Categorical Data in 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.

Working with Categorical Data in 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.

Working with Categorical Data in 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
Working with Categorical Data in 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.

Working with Categorical Data in 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()
Working with Categorical Data in Python

Finished product

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

Working with Categorical Data in Python

catplot() practice

Working with Categorical Data in Python

Preparing Video For Download...