Seaborn Assignment– 3
Distribution Plots
Basic Questions
- Load tips; plot a histogram of total_bill with bins=20 using sns.histplot.
- Using tips, draw a KDE of total_bill with fill=True and default bandwidth.
- Add a rugplot below a histogram of tip to show individual observations.
- Plot a cumulative histogram of total_bill (cumulative=True) with stat=”probability”.
- Plot a step histogram of total_bill using element=”step” and fill=False.
- Overlay histogram and KDE for total_bill in one axes; ensure y-axis is density (stat=”density”).
- Compare lunch vs dinner distributions: overlay two KDE curves of total_bill with hue=”time”.
- Draw side-by-side histograms (multiple=”dodge”) for tip by smoker.
- Plot an ECDF (sns.ecdfplot) for total_bill.
- Plot ECDFs of total_bill split by sex using hue=”sex”.
- Load penguins; plot a histogram of flipper_length_mm with binwidth=5.
- Using penguins, plot a KDE of bill_depth_mm by species with common_norm=False.
- Load iris; draw sns.jointplot(kind=”scatter”) for sepal_length vs sepal_width.
- Using iris, plot sns.jointplot(kind=”kde”, fill=True) for petal_length vs petal_width.
- Create a pairplot on iris colored by species.
- Plot a histogram of synthetic normal data (np.random.randn(500)) with bins=30.
- Overlay two distributions: normal vs uniform (500 each) as KDE curves; add legend.
- Plot a rug plot for iris[“sepal_length”] beneath a KDE of the same variable.
- Draw a histogram of tips[“size”] as discrete bins by setting discrete=True.
- Save any one distribution figure as PNG and SVG.
Intermediate Questions
- On tips, show a stacked histogram of total_bill by smoker using multiple=”stack”; keep stat=”proportion”.
- Plot two KDEs of total_bill with different smoothing: bw_adjust=0.5 vs bw_adjust=2; overlay and label.
- Create a 2×2 figure comparing: (a) hist, (b) hist+KDE, (c) step-hist, (d) cumulative-hist for tip.
- Use sns.ecdfplot to compare ECDFs of total_bill for day categories; add vertical line at the median.
- Draw sns.jointplot(kind=”hex”) for total_bill vs tip with colormap “mako”.
- Using penguins, make a jointplot(kind=”hist”) for bill_length_mm vs bill_depth_mm and set bins=25.
- Build a PairGrid on iris with upper=kde, lower=scatter, diagonal=histplot; color by species.
- For tips, plot a histogram of total_bill with binrange=(0, 60) and binwidth=3; annotate mean and median.
- Compare probability vs density scaling: two histplots of tip, one with stat=”probability”, one with stat=”density”.
- Create a cumulative KDE for total_bill (cumulative=True) and compare to cumulative histogram on the same axes.
- Plot 2D KDE (sns.kdeplot) for tips (x=total_bill, y=tip) with levels=6 and fill=True.
- Build a small dashboard: left—hist of total_bill, right—ECDF of total_bill; share y-grid style and titles.
- Using penguins, plot overlaid KDEs of body_mass_g by sex; set common_grid=True and cut=0.
- Create a facet of histograms of total_bill using col=”day”; keep identical binwidth.
- Draw a rugplot on both axes of a joint distribution: add rug=True to a jointplot(kind=”kde”).
- 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.
- Plot ECDFs of tip_pct by smoker and annotate the 0.9-quantile on each curve.
- Simulate two normal samples with different variances; plot KDEs with common_norm=False and compare spreads.
- Create a step histogram with multiple=”layer” for penguins[“flipper_length_mm”] split by species; add semi-transparent fills.
- Plot a histogram of tips[“total_bill”] on a log x-scale (set xscale to “log”); adjust bins to suit.
Advanced Questions
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.