Seaborn Assignment– 7

Multi-Plot Grids & Faceting

Basic Questions

  1. Using tips, create a FacetGrid with columns by time and map a histplot of total_bill (same binwidth in all facets).
  2. With tips, build a FacetGrid with rows by smoker, columns by sex; map a scatterplot of total_bill vs tip.
  3. Using penguins, create a FacetGrid with col=”species” and map a kdeplot of flipper_length_mm (filled).
  4. On penguins, create a FacetGrid with row=”island” and map a boxplot of body_mass_g by sex.
  5. Using iris, create a PairGrid and map histplot on the diagonal and scatterplot on the off-diagonals.
  6. With iris, create a PairGrid colored by species and map kdeplot (filled) on lower, scatterplot on upper.
  7. Using tips, create a relplot(kind=”scatter”) faceted by row=”smoker”, col=”day” for total_bill vs tip.
  8. Using tips, create a catplot(kind=”bar”) of mean tip by day with col=”time”.
  9. With penguins, create a catplot(kind=”violin”) of bill_depth_mm by sex faceted by species.
  10. Using flights, create a relplot(kind=”line”) of passengers vs year with col=”month” and col_wrap=4.
  11. With tips, create a FacetGrid (col=”day”) and map a regplot of total_bill vs tip in each facet.
  12. Using penguins, create a FacetGrid (row=”sex”) and map a stripplot of body_mass_g by species.
  13. On tips, create a FacetGrid (row=”smoker”, col=”time”) and map kdeplot of tip with fill=True.
  14. Using iris, create a PairGrid and map kdeplot contours on upper, kdeplot filled on lower, histplot on diagonal.
  15. With tips, create a FacetGrid (col=”day”) and map countplot of size.
  16. Using penguins, create a FacetGrid (col=”species”) and map boxplot of bill_length_mm by island.
  17. On tips, create a FacetGrid (row=”sex”) and map a pointplot of mean tip by day.
  18. Using iris, create a PairGrid colored by species and map regplot on upper, residplot on lower, histplot on diagonal.
  19. With any dataset, create a FacetGrid and set custom height=3, aspect=1.2; map a scatterplot.
  20. Save one FacetGrid and one PairGrid figure to PNG and SVG (same code cell/script).

Intermediate Questions

  1. Using tips, create a FacetGrid (row=”smoker”, col=”day”) and map_dataframe a custom function that plots scatterplot plus a lineplot of binned means.
  2. With penguins, create a FacetGrid (col=”species”) and map_dataframe add facet titles showing n per facet via ax.text.
  3. Using iris, create a PairGrid and map three functions: scatterplot (upper), kdeplot (lower, filled), histplot (diag); add a shared legend.
  4. On tips, create a FacetGrid (col=”time”) and map boxplot of tip by day; rotate x-ticks for readability.
  5. With flights, create a relplot(kind=”line”) faceted by row=”decade” (derived from year) and col=”quarter” (derived from month).
  6. Using penguins, create a FacetGrid (row=”sex”, col=”island”) and map_dataframe draw a violinplot with inner=”quartile” plus an overlaid stripplot.
  7. With tips, create a FacetGrid (col=”day”) and map_dataframe compute and draw a vertical line at the median total_bill in each facet.
  8. Using iris, build a PairGrid and customize different palettes per species via hue_kws; map scatterplot and ensure consistent alpha.
  9. On tips, create a FacetGrid (row=”smoker”, col=”time”) and map_dataframe draw regplot with ci=None; add shared suptitle.
  10. With penguins, create a FacetGrid (col=”species”) and map_dataframe add an annotation of mean body_mass_g inside each facet.
  11. Using iris, construct a PairGrid and map sns.residplot on lower with a linear model between pairs; diagonal as kdeplot.
  12. 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.
  13. Using penguins, create a FacetGrid and map_dataframe draw lineplot of bill_length_mm across sorted flipper_length_mm (grouped per facet).
  14. With tips, create a FacetGrid (col=”day”) and map_dataframe add a kdeplot (filled) and overlay its peak as a marker.
  15. Using iris, create a PairGrid and map correlation coefficients as annotated text on the upper triangle; keep hist on diag.
  16. 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.
  17. Using penguins, create a FacetGrid with custom margin_titles=True and despine=False; map stripplot.
  18. On tips, create a FacetGrid (row=”smoker”, col=”day”) and map_dataframe draw countplot of size; normalize to proportions by precomputing percentages before plotting.
  19. 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).
  20. 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

  1. 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.

  2. 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.

  3. 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.

  4. 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”).

  5. 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.

  6. 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

  7. 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

  8. 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.

  9. 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.

  10. 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.