Seaborn Assignment– 1

Seaborn Basics

Basic Questions

  1. Load the built-in tips dataset with sns.load_dataset; show the first 5 rows and plot total bill distribution using sns.histplot.
  2. Load the penguins dataset; drop rows with missing values and plot a scatter of flipper_length_mm vs bill_length_mm.
  3. From tips, create a bar plot of average tip by day using sns.barplot; show exact values as axis ticks.
  4. Using penguins, draw a categorical count plot (sns.countplot) for species.
  5. From tips, plot a boxplot of total_bill by day.
  6. Using tips, create a violin plot of total_bill by time (Lunch/Dinner).
  7. Load iris dataset; create a KDE plot (sns.kdeplot) of sepal_length.
  8. From iris, create a histogram with sns.histplot and overlay KDE.
  9. Using tips, draw a relational sns.scatterplot of total_bill vs tip colored by smoker.
  10. Using tips, plot a sns.lineplot of cumulative sum of total_bill over row index.
  11. From penguins, make a sns.stripplot of body_mass_g by species.
  12. Using penguins, create a sns.swarmplot of body_mass_g by sex.
  13. Load flights dataset and show a heatmap of passengers by month vs year with sns.heatmap.
  14. From tips, use sns.jointplot (kind=”scatter”) for total_bill and tip.
  15. With iris, plot pairwise relationships using sns.pairplot colored by species.
  16. Using any dataset, switch to Seaborn theme sns.set_theme(style=”whitegrid”) and re-plot a recent chart.
  17. From tips, create a sns.pointplot showing mean tip by day with confidence intervals.
  18. Using penguins, draw a sns.boxenplot for bill_depth_mm by species.
  19. Create a sns.countplot for tips[‘sex’] and annotate bar counts above each bar.
  20. Save one of your plots as PNG and SVG from the same figure object.

Intermediate Questions

  1. Load tips; create a sns.catplot(kind=”bar”) of mean total_bill by day, split by sex using hue.
  2. Using penguins, build a sns.relplot(kind=”scatter”) mapping size to body_mass_g and color to species.
  3. From flights, pivot to year×month matrix and plot a heatmap with custom colormap and labeled cells.
  4. With tips, compare sns.boxplot and sns.violinplot for total_bill by day in a 1×2 figure; keep a shared y-axis.
  5. Using iris, draw sns.jointplot(kind=”hex”) for sepal_length vs sepal_width.
  6. Load penguins; create a pairplot with different diag kind (kde) and off-diagonal kind (scatter).
  7. From tips, create sns.lmplot (scatter + regression) for total_bill vs tip with hue=”smoker”.
  8. Using tips, construct a FacetGrid with columns by time and rows by smoker, mapping a histplot of tip.
  9. Apply sns.set_style(“ticks”) and sns.set_context(“talk”); plot a scatterplot and compare typography vs default.
  10. Using penguins, create a catplot(kind=”swarm”) by species and sex; rotate x-tick labels for readability.
  11. From tips, compute a grouped Pandas DataFrame of mean/median total_bill by day; plot both as a layered lineplot.
  12. Using flights, plot a lineplot of passengers over years with style=”month” to get multiple monthly lines.
  13. With iris, build a displot (figure-level) showing histogram + KDE for petal_length with col=”species”.
  14. Switch palette globally to “mako” then draw a multi-series lineplot; verify color cycling.
  15. Create a custom palette from a list of hex colors and apply it to a barplot.
  16. Using tips, draw barplot with estimator=np.median and ci=None; annotate median values.
  17. From penguins, create two vertically stacked axes: top boxplot by species; bottom stripplot overlaid on same categories.
  18. Build a figure-level catplot(kind=”point”) with capsize=.2 and compare to an axes-level pointplot style on another axes.
  19. Using tips, demonstrate theme anatomy: set a figure title with fig.suptitle, axes titles with set_title, and apply margin adjustments to avoid overlap.
  20. Create a reusable plotting function that takes a DataFrame and column names, and draws either a boxplot or violinplot based on a parameter.

Advanced Questions

  1. Figure/Theme Anatomy:
    Create a publication-ready Seaborn theme using set_theme(context="paper", style="whitegrid", font_scale=1.2).
    Generate a 2×2 grid combining categorical, relational, distributional, and heatmap plots with a shared suptitle and consistent palette.

  2. Figure- vs Axes-level API:
    Using the tips dataset, reproduce the same categorical plot once with catplot (figure-level) and once with boxplot (axes-level) inside a custom matplotlib.figure.Figure.
    Discuss differences in layout control via code (suptitle, tight layout).

  3. Pandas Integration:
    Build a preprocessing pipeline (drop NA, groupby, aggregate, reset_index) on the penguins dataset. Then plot:

    • Grouped bar of mean body_mass_g by species × sex

    • Swarm of raw points for the same categories below it
      Align x categories between both plots.

  4. Relational Faceting:
    With the flights dataset, create a relplot(kind="line") faceted by row="month", colored by decade (derived column).
    Add a legend and tidy tick formatting.

  5. Distribution Suite:
    On a single figure with subplots, render histplot, kdeplot, ecdfplot, and rugplot for the same numeric series.
    Unify x-limits and annotate mean/median lines.

  6. Mixed Anatomy Dashboard:
    Compose a dashboard-style figure with four panels:

    • A: lineplot of rolling average

    • B: barplot of category totals

    • C: heatmap of correlations

    • D: scatterplot with regression
      Apply one global theme and palette consistently. Export to PNG and SVG.

  7. Custom Palettes:
    Create a ListedColormap-backed palette with 6 tones.
    Apply it to three different plot types and include a legend color key subplot explaining the palette mapping.

  8. PairGrid Customization:
    Build a PairGrid on the iris dataset with custom mappings:

    • Upper: scatter + regplot

    • Lower: filled kdeplot

    • Diagonal: histplot
      Adjust despine and theme, then save as high-DPI.

  9. Aesthetic Controls:
    Use sns.set_context variations (paper, talk, poster) to render the same multi-series lineplot three times.
    Arrange them vertically in one figure and label each context on the axes.

  10. End-to-End Report:
    Load two datasets (tips, penguins). Create a 4-page PDF via PdfPages:

  • Page 1: dataset overviews (tables rendered via Matplotlib text)

  • Page 2: categorical comparisons

  • Page 3: relational facets

  • Page 4: distribution + heatmap
    Maintain one theme and palette across all pages for a cohesive report.