Seaborn Assignment– 5

Relational Plots

Basic Questions

  1. Using tips, draw a scatterplot of total_bill vs tip with default settings.
  2. From tips, draw a scatterplot with hue=”sex” and add a legend.
  3. Using penguins, draw a scatterplot of bill_length_mm vs bill_depth_mm colored by species.
  4. With penguins, draw a scatterplot adding style=”sex” and size=”body_mass_g” simultaneously.
  5. Using tips, draw a lineplot of cumulative total_bill over row index; show default confidence interval.
  6. From any small synthetic time series (30 daily points), draw a lineplot and set ci=None.
  7. Using tips, plot relplot(kind=”scatter”) of total_bill vs tip faceted by time (columns).
  8. Using penguins, draw a relplot(kind=”scatter”) with col=”island” and hue=”species”.
  9. Create a lineplot of monthly values (12 points) with markers enabled (marker=”o”).
  10. Using tips, draw a scatterplot and map tip percentage (tip/total_bill) to size=.
  11. With flights, aggregate passengers by year and draw a lineplot of passengers vs year.
  12. Using flights, draw a relplot(kind=”line”) with col=”month” for passengers over years.
  13. Using a synthetic dataset with three categories, draw a lineplot using style=”category” to change linestyles.
  14. From penguins, draw a scatterplot and enable transparency with alpha=0.6.
  15. Using tips, draw a relplot(kind=”scatter”) with row=”smoker” and col=”time”.
  16. Create a lineplot with err_style=”band”; then repeat with err_style=”bars” on another axes.
  17. Using tips, draw a scatterplot and set palette=”deep”; compare to default colors.
  18. With penguins, draw a lineplot of flipper_length_mm vs row index grouped by species using hue.
  19. Using flights, draw a lineplot of passengers by month for a single year; rotate x-ticks 45°.
  20. Save any one relational plot as PNG and SVG from the same figure.

Intermediate Questions

  1. Using tips, draw a scatterplot with hue=”day” and style=”time”; place the legend outside using bbox_to_anchor.
  2. From tips, compute tip_pct = tip/total_bill and draw a lineplot of mean tip_pct by day with ci=95.
  3. Using penguins, draw a scatterplot with hue=”species” and size=”body_mass_g”; cap sizes via sizes=(20, 200).
  4. Build a relplot(kind=”line”) on flights with col=”month” and row=”decade” (derived from year); ensure consistent ylim.
  5. Using tips, draw a lineplot of rolling mean (window=5) of total_bill over index; show ci=None and markers.
  6. From penguins, draw relplot(kind=”scatter”) with col=”sex” and row=”island”; share axes across facets.
  7. Using flights, draw a multi-series lineplot (one line per month) for a selected decade; add a legend with 12 entries.
  8. Create a scatterplot with a third quantitative variable mapped to color using hue= and palette=”viridis”; add a colorbar via hue_norm.
  9. On tips, draw two subplots: (A) scatterplot with hue=”smoker”, (B) lineplot of mean tip by day with hue=”smoker”; align titles.
  10. Using penguins, draw a relplot(kind=”line”) showing mean flipper_length_mm by species across islands (hue=”species”, col=”island”).
  11. With synthetic data containing time, group, and value, draw a lineplot with style=”group” and dashes=True.
  12. Using tips, draw a scatterplot of total_bill vs tip and encode party size with size=; adjust sizes and add alpha=.6.
  13. Build a relplot(kind=”line”) on flights with facet_kws={“sharey”: False}; annotate the max passenger point on each facet.
  14. Using penguins, create a scatterplot with hue=”species” and add sns.move_legend(ax, “upper left”, bbox_to_anchor=(1,1)) (or equivalent).
  15. From tips, draw a lineplot of mean total_bill by day with bootstrapped confidence intervals (n_boot higher than default).
  16. Using flights, create a relplot(kind=”line”) with row=”month” and col_wrap=4; use height=2.2 for compact panels.
  17. Build a scatterplot where outliers are annotated: compute z-scores for tip_pct and annotate points with |z|>2.
  18. Using a generated long-format time series (3 categories × 100 steps), draw a lineplot with hue and style; add markers every 10th point only.
  19. Create a relplot(kind=”scatter”) mapping hue and size to the same quantitative variable; explain the legend by enabling the size legend.
  20. Using penguins, draw a scatterplot and add sns.regplot (Matplotlib/seaborn compatible) on a second axes for comparison of trend depiction.

Advanced Questions

  1. Time-Series Case Study (A):
    From the flights dataset, engineer a tidy DataFrame with date (datetime), passengers, month, year, and decade.
    Build a relplot(kind="line") faceted by row="decade", colored by month.
    Unify y-limits, add a suptitle, and export to PNG and PDF.

  2. Time-Series Case Study (B):
    Using synthetic hourly data for 7 days, create a dashboard with:

    • Top: lineplot of raw series (alpha=.4)

    • Middle: lineplot of 3-hour rolling mean with ci=None

    • Bottom: scatterplot of flagged anomalies
      Share the x-axis and add vertical weekend bands.

  3. High-Dimensional Encoding:
    Build a scatterplot where hue encodes a category, style encodes a second category, and size encodes a quantitative score.
    Ensure the legend is readable, grouping entries with proxy artists if needed.

  4. Relational Facets Deep-Dive:
    Create a relplot(kind="line") of multiple groups across time with col="region" and row="product".
    Synchronize color identity across all facets and add a single shared legend outside the grid.

  5. Trend + Uncertainty:
    Simulate 20 realizations of a noisy trend.
    Plot a lineplot of the mean with a 95% confidence band and overlay individual thin lines (alpha=.15) to show distribution context.

  6. Regressive Trends:
    On the tips dataset, produce a two-panel figure:

    • Left: scatterplot (total_bill vs tip) with hue=”sex”

    • Right: regplot with polynomial order=2
      Harmonize axes and palettes across both panels.

  7. Temporal Decomposition View:
    Generate a time series y(t) = trend + seasonality + noise.
    Render three aligned lineplots for each component and a combined plot.
    Annotate peaks and troughs, then export the figure.

  8. Facet Grid Annotations:
    With the flights dataset, build a relplot(kind="line") faceted by month.
    Annotate each facet with the year having maximum passengers and draw a horizontal reference line at the decade median.

  9. Performance & Readability:
    For 100k synthetic points (x, y, t), compare two approaches:

    • (A) Single scatterplot with alpha=0.05

    • (B) relplot faceted by time buckets
      Measure and print the render time for each approach.

  10. Publish-Ready Time-Series Panel:
    Create a 2×2 panel layout:

    • A: multi-series lineplot with confidence intervals

    • B: scatterplot with hue and size encodings

    • C: faceted relplot(kind="line")

    • D: zoomed-in lineplot for a selected window
      Apply one theme, a unified palette, labeled axes, and a shared legend outside. Export at 300 DPI in PNG and SVG.