Building Multi-Plot Grids
ã¡ãã¥ãŒã衚瀺ããã«ã¯ã¹ã¯ã€ãããŠãã ãã
A FacetGrid is the fundamental structure that allows you to create a matrix of plots defined by categorical variables.
Think of it as a two-step process:
- Build the grid: you define the "skeleton" (rows and columns) based on your data. At this stage, the plots are empty;
- Map the data: you use the
.map()method to "paint" a specific type of plot (histogram, scatter, etc.) onto every cell in that grid.
The Workflow
# Step 1: Initialize the grid
# This creates empty subplots: one for each 'time' (Lunch/Dinner)
g = sns.FacetGrid(data=df, col='time')
# Step 2: Map a plot onto the grid
# This draws a histogram of 'total_bill' in every empty subplot
g.map(sns.histplot, 'total_bill')
Key Parameters
col/row: the variables that define the grid structure;height: height (in inches) of each individual facet (subplot);.map(func, *args, **kwargs):func: the plotting function to use (e.g.,sns.histplot,plt.scatter);*args: the column names to plot (e.g.,'total_bill');**kwargs: styling arguments (e.g.,color='red').
ã¿ã¹ã¯
ã¹ã¯ã€ãããŠã³ãŒãã£ã³ã°ãéå§
Analyze the distribution of total bills, breaking it down by day and smoking status.
- Set the style to
'whitegrid'. Set the background color to'cornsilk'('axes.facecolor'). - Initialize the FacetGrid (
g):- Use the
tipsdataset (df). - Create a column for each
'day'. - Create a row for each
'smoker'status. - Set the
heightof each subplot to3.
- Use the
- Map a histogram onto this grid:
- Use
sns.histplotas the plotting function. - Plot the
'total_bill'variable. - Set the
colorto'olive'. - Add a KDE curve (
kde=True). - Remove the bar filling (
fill=False) to see the outline better. - Set the
binwidthto4.
- Use
- Display the plot.
è§£ç
ãã¹ãŠæç¢ºã§ãããïŒ
ãã£ãŒãããã¯ããããšãããããŸãïŒ
ã»ã¯ã·ã§ã³Â 1. ç« Â 18
single
AIã«è³ªåãã
AIã«è³ªåãã
äœã§ã質åããããææ¡ããã質åã®1ã€ã詊ããŠãã£ãããå§ããŠãã ãã