Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
学ぶ Mastering the Categorical Interface | Section
Statistical Visualization with Seaborn
セクション 1.  15
single

single

bookMastering the Categorical Interface

メニューを表示するにはスワイプしてください

The catplot (categorical plot) is the general figure-level interface that gives you access to every categorical plot we've learned so far (stripplot, boxplot, violinplot, barplot, etc.).

Why use Catplot?

Just like displot, the main superpower of catplot is faceting. You can easily split your analysis into multiple subplots based on a categorical variable using row and col.

Key Parameters

  • kind: the name of the plot type you want to draw. Defaults to 'strip', but you can set it to:
    • 'swarm', 'box', 'violin', 'boxen', 'point', 'bar', 'count'.
  • row / col: variables that define subsets to plot on different facets (subplots);
  • legend_out: if True (default), the legend is drawn outside the plot area to prevent it from covering data.

Live Example

Here we create a Boxplot for each time of day (Lunch/Dinner) automatically using col.

123456789101112131415161718
import seaborn as sns import matplotlib.pyplot as plt # Load dataset df = sns.load_dataset('tips') # Create a grid of boxplots sns.catplot( data=df, hue='day', x='day', y='total_bill', col='time', # Split into 2 columns (Lunch/Dinner) kind='box', # Draw boxplots palette='Set3' ) plt.show()
copy
タスク

スワイプしてコーディングを開始

Visualize the body mass of penguins across different islands and species.

  1. Set the style to 'white'. Customize the background color to 'aliceblue' ('axes.facecolor').
  2. Create a catplot using the penguins dataset (df):
    • Map 'species' to x and 'body_mass_g' to y.
    • Color points by 'sex' using hue.
    • Split the plot into rows based on the 'island' variable using row.
    • Use the 'viridis' palette.
    • Set point transparency alpha to 0.6.
    • Move the legend inside the plot by setting legend_out=False.
  3. Display the plot.

解答

Switch to desktop実践的な練習のためにデスクトップに切り替える下記のオプションのいずれかを利用して、現在の場所から続行する
すべて明確でしたか?

どのように改善できますか?

フィードバックありがとうございます!

セクション 1.  15
single

single

AIに質問する

expand

AIに質問する

ChatGPT

何でも質問するか、提案された質問の1つを試してチャットを始めてください

some-alt