Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
学ぶ Combining Regression and Grids | Section
Statistical Visualization with Seaborn
セクション 1.  22
single

single

bookCombining Regression and Grids

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

The lmplot (linear model plot) is a figure-level function that combines regplot and FacetGrid.

While regplot is great for a single relationship, lmplot allows you to compare linear relationships across different categories. You can separate data by color (hue) or by splitting it into different subplots (col/row), making it powerful for answering questions like "Does the relationship between bill and tip change if the customer is a smoker?" .

Key Parameters

  • hue: separating the data by color and drawing a separate regression line for each group;
  • col / row: separating the data into distinct subplots;
  • markers: a list of symbols to distinguish groups visually (e.g., ['o', 'x']), which is helpful for accessibility.

Example

Here we compare the tips given during Lunch vs. Dinner. Notice how col splits the view, while hue compares smokers within each view.

1234567891011121314151617
import seaborn as sns import matplotlib.pyplot as plt # Load dataset df = sns.load_dataset('tips') # Create a grid of regression plots sns.lmplot( data=df, x='total_bill', y='tip', col='time', # Split: Lunch vs Dinner hue='smoker', # Color: Yes vs No palette='Set1' ) plt.show()
copy
タスク

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

Analyze the tips dataset to see how gender and smoking status affect tipping behavior.

  1. Set the style to 'darkgrid'. Set the figure background color to 'lightpink'.
  2. Create an lmplot using the tips dataset (df):
    • Map 'total_bill' to x and 'tip' to y.
    • Color the lines based on 'smoker' status (hue).
    • Split the visualization into columns based on 'sex' (col).
    • Use distinct markers: 'o' for the first group and 'x' for the second.
    • Use the 'crest' palette.
  3. Display the plot.

解答

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

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

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

セクション 1.  22
single

single

AIに質問する

expand

AIに質問する

ChatGPT

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

some-alt