Seaborn Assignment– 7
Multi-Plot Grids & Faceting
Basic Questions
- Using tips, create a FacetGrid with columns by time and map a histplot of total_bill (same binwidth in all facets).
- With tips, build a FacetGrid with rows by smoker, columns by sex; map a scatterplot of total_bill vs tip.
- Using penguins, create a FacetGrid with col=”species” and map a kdeplot of flipper_length_mm (filled).
- On penguins, create a FacetGrid with row=”island” and map a boxplot of body_mass_g by sex.
- Using iris, create a PairGrid and map histplot on the diagonal and scatterplot on the off-diagonals.
- With iris, create a PairGrid colored by species and map kdeplot (filled) on lower, scatterplot on upper.
- Using tips, create a relplot(kind=”scatter”) faceted by row=”smoker”, col=”day” for total_bill vs tip.
- Using tips, create a catplot(kind=”bar”) of mean tip by day with col=”time”.
- With penguins, create a catplot(kind=”violin”) of bill_depth_mm by sex faceted by species.
- Using flights, create a relplot(kind=”line”) of passengers vs year with col=”month” and col_wrap=4.
- With tips, create a FacetGrid (col=”day”) and map a regplot of total_bill vs tip in each facet.
- Using penguins, create a FacetGrid (row=”sex”) and map a stripplot of body_mass_g by species.
- On tips, create a FacetGrid (row=”smoker”, col=”time”) and map kdeplot of tip with fill=True.
- Using iris, create a PairGrid and map kdeplot contours on upper, kdeplot filled on lower, histplot on diagonal.
- With tips, create a FacetGrid (col=”day”) and map countplot of size.
- Using penguins, create a FacetGrid (col=”species”) and map boxplot of bill_length_mm by island.
- On tips, create a FacetGrid (row=”sex”) and map a pointplot of mean tip by day.
- Using iris, create a PairGrid colored by species and map regplot on upper, residplot on lower, histplot on diagonal.
- With any dataset, create a FacetGrid and set custom height=3, aspect=1.2; map a scatterplot.
- Save one FacetGrid and one PairGrid figure to PNG and SVG (same code cell/script).
Intermediate Questions
- Using tips, create a FacetGrid (row=”smoker”, col=”day”) and map_dataframe a custom function that plots scatterplot plus a lineplot of binned means.
- With penguins, create a FacetGrid (col=”species”) and map_dataframe add facet titles showing n per facet via ax.text.
- Using iris, create a PairGrid and map three functions: scatterplot (upper), kdeplot (lower, filled), histplot (diag); add a shared legend.
- On tips, create a FacetGrid (col=”time”) and map boxplot of tip by day; rotate x-ticks for readability.
- With flights, create a relplot(kind=”line”) faceted by row=”decade” (derived from year) and col=”quarter” (derived from month).
- Using penguins, create a FacetGrid (row=”sex”, col=”island”) and map_dataframe draw a violinplot with inner=”quartile” plus an overlaid stripplot.
- With tips, create a FacetGrid (col=”day”) and map_dataframe compute and draw a vertical line at the median total_bill in each facet.
- Using iris, build a PairGrid and customize different palettes per species via hue_kws; map scatterplot and ensure consistent alpha.
- On tips, create a FacetGrid (row=”smoker”, col=”time”) and map_dataframe draw regplot with ci=None; add shared suptitle.
- With penguins, create a FacetGrid (col=”species”) and map_dataframe add an annotation of mean body_mass_g inside each facet.
- Using iris, construct a PairGrid and map sns.residplot on lower with a linear model between pairs; diagonal as kdeplot.
- With tips, create a catplot(kind=”bar”) of mean tip_pct = tip/total_bill by day and facet by sex; add caps on error bars.
- Using penguins, create a FacetGrid and map_dataframe draw lineplot of bill_length_mm across sorted flipper_length_mm (grouped per facet).
- With tips, create a FacetGrid (col=”day”) and map_dataframe add a kdeplot (filled) and overlay its peak as a marker.
- Using iris, create a PairGrid and map correlation coefficients as annotated text on the upper triangle; keep hist on diag.
- With flights, create a relplot(kind=”line”) and facet by month; ensure shared y-limits and add a horizontal reference line at the overall median passengers.
- Using penguins, create a FacetGrid with custom margin_titles=True and despine=False; map stripplot.
- On tips, create a FacetGrid (row=”smoker”, col=”day”) and map_dataframe draw countplot of size; normalize to proportions by precomputing percentages before plotting.
- Using iris, build a PairGrid and on lower triangle map a custom function that draws scatterplot and a lowess trend (sns.regplot(lowess=True, scatter=False) via map_dataframe).
- With any dataset, create a FacetGrid and implement shared legend outside the grid (collect handles from one facet and place using bbox_to_anchor).
Advanced Questions
EDA Grid (Tips): Build a 2×3 FacetGrid dashboard for tips:
A: histplot of total_bill
B: histplot of tip
C: catplot-style bar of mean tip_pct by day
D: scatterplot total_bill vs tip with hue=”smoker”
E: boxplot of total_bill by time
F: kdeplot of tip_pct
Add a shared suptitle, consistent palette, and export PNG & PDF.
PairGrid Diagnostics (Iris): Create a PairGrid with:
Upper: regplot (linear fits)
Lower: kdeplot contours
Diagonal: histplot
Annotate each upper cell with slope from np.polyfit.
Facet-Based Summaries (Penguins): Build a FacetGrid (row=”island”, col=”sex”) mapping scatterplot of bill_length_mm vs bill_depth_mm. Overlay facet-level mean lines (horizontal and vertical) and display facet counts.
Custom Mapper: Write a reusable function for map_dataframe that:
Scatters points
Draws a regression line without CI
Writes R² in the corner
Apply across tips facets (row=”smoker”, col=”time”).
High-Dim Facets (Flights): Engineer decade, quarter, and is_peak_season flags. Create a
relplot(kind="line")
with row=”decade”, col=”quarter”, hue=”is_peak_season”. Unify y-limits and put one legend outside.Hybrid Grid: For penguins, create a PairGrid.
Upper: scatterplot with jitter
Lower: violin plots via a helper that reshapes pair columns into long-form per facet before plotting
Correlation Grid with Significance: On iris, compute pairwise Pearson r and p-values. Create a PairGrid:
Upper: show r annotated, background-colored by magnitude
Diagonal: histplots
Lower: blank
Mixed-Type Facet EDA (Tips): Create a FacetGrid (col=”day”) with map_dataframe to:
Draw boxplot of tip_pct by sex
Overlay stripplot
Add per-facet median line of tip_pct.
Performance Faceting: Generate a long synthetic dataset (≥50k rows, columns: group, time, value). Build
relplot(kind="line")
faceted by group with col_wrap=4. Measure render time and print it as figure text.Publish-Ready EDA Report: Assemble a multi-page PDF via PdfPages:
Page 1: dataset overview text + FacetGrid histograms
Page 2: PairGrid mixed mappings
Page 3: facet scatter + per-facet regression summaries
Keep one theme, put legends outside, label panels (A–C), and save at 300 DPI.