セクション 1. 章 20
single
Creating 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
- Initialize: create the grid with your data and variables. At this point, it is empty;
g.plot_joint(): draws the bivariate plot in the center (e.g., scatter plot);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.
1234567891011121314import 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()
タスク
スワイプしてコーディングを開始
Analyze the relationship between bill length and depth, distinguishing by species.
- Set the style to
'ticks'. Change the figure background color to'lightcyan'('figure.facecolor'). - Initialize the
JointGrid(g):- Map
'bill_length_mm'toxand'bill_depth_mm'toy. - Color points by
'species'(hue). - Use the
'viridis'palette.
- Map
- 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) to1.
- Draw a
- Side plots (
plot_marginals):- Draw a
histplot. - Add a KDE curve (
kde=True).
- Draw a
- Display the plot.
解答
すべて明確でしたか?
フィードバックありがとうございます!
セクション 1. 章 20
single
AIに質問する
AIに質問する
何でも質問するか、提案された質問の1つを試してチャットを始めてください