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

single

bookCreating Joint Distribution Plots

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

JointGrid is the underlying figure-level object used to create bivariate plots with marginal univariate plots.

When you use sns.jointplot(), it creates a JointGrid for you automatically. However, using JointGrid directly gives you a blank canvas. You can explicitly decide what to draw in the center and what to draw on the sides.

The Workflow

  1. Initialize: create the grid with your data and variables. At this point, it is empty;
  2. g.plot_joint(): draws the bivariate plot in the center (e.g., scatter plot);
  3. g.plot_marginals(): draws the univariate plots on the top and right axes (e.g., histogram or KDE).

Example

Here we create a custom grid with a regression plot in the center and KDE curves on the sides.

1234567891011121314
import seaborn as sns import matplotlib.pyplot as plt # Load dataset df = sns.load_dataset('penguins') # 1. Initialize the grid g = sns.JointGrid(data=df, x='bill_length_mm', y='bill_depth_mm') # 2. Draw the plots g.plot_joint(sns.regplot, scatter_kws={'alpha': 0.5}) # Center: Regression g.plot_marginals(sns.kdeplot, fill=True) # Sides: KDE plt.show()
copy
タスク

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

Analyze the relationship between bill length and depth, distinguishing by species.

  1. Set the style to 'ticks'. Change the figure background color to 'lightcyan' ('figure.facecolor').
  2. Initialize the JointGrid (g):
    • Map 'bill_length_mm' to x and 'bill_depth_mm' to y.
    • Color points by 'species' (hue).
    • Use the 'viridis' palette.
  3. Center plot (plot_joint):
    • Draw a scatterplot.
    • Make points semi-transparent (alpha=0.5).
    • Set point border color (edgecolor) to 'pink'.
    • Set border thickness (linewidth) to 1.
  4. Side plots (plot_marginals):
    • Draw a histplot.
    • Add a KDE curve (kde=True).
  5. Display the plot.

解答

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

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

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

セクション 1.  20
single

single

AIに質問する

expand

AIに質問する

ChatGPT

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

some-alt