Seaborn Assignment– 3

Distribution Plots

Basic Questions

  1. Load tips; plot a histogram of total_bill with bins=20 using sns.histplot.
  2. Using tips, draw a KDE of total_bill with fill=True and default bandwidth.
  3. Add a rugplot below a histogram of tip to show individual observations.
  4. Plot a cumulative histogram of total_bill (cumulative=True) with stat=”probability”.
  5. Plot a step histogram of total_bill using element=”step” and fill=False.
  6. Overlay histogram and KDE for total_bill in one axes; ensure y-axis is density (stat=”density”).
  7. Compare lunch vs dinner distributions: overlay two KDE curves of total_bill with hue=”time”.
  8. Draw side-by-side histograms (multiple=”dodge”) for tip by smoker.
  9. Plot an ECDF (sns.ecdfplot) for total_bill.
  10. Plot ECDFs of total_bill split by sex using hue=”sex”.
  11. Load penguins; plot a histogram of flipper_length_mm with binwidth=5.
  12. Using penguins, plot a KDE of bill_depth_mm by species with common_norm=False.
  13. Load iris; draw sns.jointplot(kind=”scatter”) for sepal_length vs sepal_width.
  14. Using iris, plot sns.jointplot(kind=”kde”, fill=True) for petal_length vs petal_width.
  15. Create a pairplot on iris colored by species.
  16. Plot a histogram of synthetic normal data (np.random.randn(500)) with bins=30.
  17. Overlay two distributions: normal vs uniform (500 each) as KDE curves; add legend.
  18. Plot a rug plot for iris[“sepal_length”] beneath a KDE of the same variable.
  19. Draw a histogram of tips[“size”] as discrete bins by setting discrete=True.
  20. Save any one distribution figure as PNG and SVG.

Intermediate Questions

  1. On tips, show a stacked histogram of total_bill by smoker using multiple=”stack”; keep stat=”proportion”.
  2. Plot two KDEs of total_bill with different smoothing: bw_adjust=0.5 vs bw_adjust=2; overlay and label.
  3. Create a 2×2 figure comparing: (a) hist, (b) hist+KDE, (c) step-hist, (d) cumulative-hist for tip.
  4. Use sns.ecdfplot to compare ECDFs of total_bill for day categories; add vertical line at the median.
  5. Draw sns.jointplot(kind=”hex”) for total_bill vs tip with colormap “mako”.
  6. Using penguins, make a jointplot(kind=”hist”) for bill_length_mm vs bill_depth_mm and set bins=25.
  7. Build a PairGrid on iris with upper=kde, lower=scatter, diagonal=histplot; color by species.
  8. For tips, plot a histogram of total_bill with binrange=(0, 60) and binwidth=3; annotate mean and median.
  9. Compare probability vs density scaling: two histplots of tip, one with stat=”probability”, one with stat=”density”.
  10. Create a cumulative KDE for total_bill (cumulative=True) and compare to cumulative histogram on the same axes.
  11. Plot 2D KDE (sns.kdeplot) for tips (x=total_bill, y=tip) with levels=6 and fill=True.
  12. Build a small dashboard: left—hist of total_bill, right—ECDF of total_bill; share y-grid style and titles.
  13. Using penguins, plot overlaid KDEs of body_mass_g by sex; set common_grid=True and cut=0.
  14. Create a facet of histograms of total_bill using col=”day”; keep identical binwidth.
  15. Draw a rugplot on both axes of a joint distribution: add rug=True to a jointplot(kind=”kde”).
  16. Use weights in histplot: create a new column tip_pct = tip/total_bill and plot a weighted histogram of total_bill weighted by tip_pct.
  17. Plot ECDFs of tip_pct by smoker and annotate the 0.9-quantile on each curve.
  18. Simulate two normal samples with different variances; plot KDEs with common_norm=False and compare spreads.
  19. Create a step histogram with multiple=”layer” for penguins[“flipper_length_mm”] split by species; add semi-transparent fills.
  20. Plot a histogram of tips[“total_bill”] on a log x-scale (set xscale to “log”); adjust bins to suit.

Advanced Questions

  1. Bandwidth Tuning Panel: For tips[“total_bill”], render four KDEs in a 2×2 grid with bw_adjust = {0.3, 0.7, 1.0, 2.0}; annotate each subplot with its value and discuss the smoothing effect via figure text.
  2. Mixture Modeling (Visual): Generate a synthetic mixture of two normals (e.g., means 0 and 4). Plot: (i) histogram (stat=”density”), (ii) KDE (bw_adjust tuned), (iii) ECDF; align x-limits.
  3. Cumulative Comparison: Draw cumulative histograms for total_bill by time (Lunch vs Dinner) and overlay cumulative KDEs; ensure lines are distinguishable and add a legend.
  4. High-Granularity Facets: Create a FacetGrid of step histograms of total_bill faceted by day and smoker (rows×cols); keep consistent binwidth and tight layout.
  5. 2D Density Suite: For tips (total_bill vs tip), produce a 3-panel figure: (a) hexbin-like jointplot(kind=”hex”), (b) filled 2D KDE with contours, (c) scatter with marginal histograms (kind=”hist”); synchronize colormaps.
  6. ECDF Diagnostics: Plot ECDF and complementary ECDF (1−F) of tip on the same axes; use log y-scale for the complementary curve to highlight tails.
  7. Pairwise Distributions Report: On penguins, create a pairplot with custom diagonal (kde) and off-diagonal (hist) and save at 300 DPI; ensure palette distinguishes species well.
  8. Quantile Bands: For total_bill, draw a KDE and shade between the 25th and 75th percentile using vertical fills; add lines at the 10th and 90th percentiles.
  9. Multiple Distributions, One Axes: Overlay KDEs for iris[“sepal_length”], iris[“sepal_width”], and iris[“petal_length”] with distinct linestyles and a shared legend; set common_norm=False.
  10. Distribution + ECDF Dashboard: Build a 2×2 grid for a chosen numeric series: (A) hist (probability), (B) step hist, (C) KDE (filled), (D) ECDF. Apply one theme and export PNG + PDF.