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

single

bookUsing the Distribution Interface

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

The displot (distribution plot) is the "parent" function for all the plots we have learned so far. It provides a single interface to create histograms, KDE plots, and ECDFs.

Why Use Displot?

While histplot and kdeplot are great for single plots, displot has a superpower: faceting.

Using the col (column) or row parameter, displot can automatically split your dataset into multiple side-by-side subplots based on a category.

Key Parameters

  • kind: determines the type of plot;
    • 'hist' (default);
    • 'kde';
    • 'ecdf'.
  • col / row: splits the data into separate subplots arranged in columns or rows.

Example

Here is how you can instantly create 3 separate histograms for different species using just one line of code.

12345678910111213141516
import seaborn as sns import matplotlib.pyplot as plt # Load dataset df = sns.load_dataset('penguins') # Create a grid of plots sns.displot( data=df, x='bill_length_mm', col='species', # Creates 3 subplots (one per species) kind='hist', # Draw histograms element='step' ) plt.show()
copy
タスク

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

Visualize the distribution of diamond carats using the diamonds dataset.

  1. Set the style to 'darkgrid'.
  2. Create a KDE plot using the displot function:
    • Set x to 'carat'.
    • Color the curves by 'cut' using hue.
    • Split the plot into separate columns based on the 'color' of the diamond using col.
    • Set the type of plot to 'kde' using the kind parameter.
    • Normalize the data using multiple='fill' to show relative proportions.
    • Use the 'viridis' palette.
    • Use the df variable as data.
  3. Display the plot.

解答

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

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

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

セクション 1.  8
single

single

AIに質問する

expand

AIに質問する

ChatGPT

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

some-alt