Seaborn Assignment– 5
Relational Plots
Basic Questions
- Using tips, draw a scatterplot of total_bill vs tip with default settings.
- From tips, draw a scatterplot with hue=”sex” and add a legend.
- Using penguins, draw a scatterplot of bill_length_mm vs bill_depth_mm colored by species.
- With penguins, draw a scatterplot adding style=”sex” and size=”body_mass_g” simultaneously.
- Using tips, draw a lineplot of cumulative total_bill over row index; show default confidence interval.
- From any small synthetic time series (30 daily points), draw a lineplot and set ci=None.
- Using tips, plot relplot(kind=”scatter”) of total_bill vs tip faceted by time (columns).
- Using penguins, draw a relplot(kind=”scatter”) with col=”island” and hue=”species”.
- Create a lineplot of monthly values (12 points) with markers enabled (marker=”o”).
- Using tips, draw a scatterplot and map tip percentage (tip/total_bill) to size=.
- With flights, aggregate passengers by year and draw a lineplot of passengers vs year.
- Using flights, draw a relplot(kind=”line”) with col=”month” for passengers over years.
- Using a synthetic dataset with three categories, draw a lineplot using style=”category” to change linestyles.
- From penguins, draw a scatterplot and enable transparency with alpha=0.6.
- Using tips, draw a relplot(kind=”scatter”) with row=”smoker” and col=”time”.
- Create a lineplot with err_style=”band”; then repeat with err_style=”bars” on another axes.
- Using tips, draw a scatterplot and set palette=”deep”; compare to default colors.
- With penguins, draw a lineplot of flipper_length_mm vs row index grouped by species using hue.
- Using flights, draw a lineplot of passengers by month for a single year; rotate x-ticks 45°.
- Save any one relational plot as PNG and SVG from the same figure.
Intermediate Questions
- Using tips, draw a scatterplot with hue=”day” and style=”time”; place the legend outside using bbox_to_anchor.
- From tips, compute tip_pct = tip/total_bill and draw a lineplot of mean tip_pct by day with ci=95.
- Using penguins, draw a scatterplot with hue=”species” and size=”body_mass_g”; cap sizes via sizes=(20, 200).
- Build a relplot(kind=”line”) on flights with col=”month” and row=”decade” (derived from year); ensure consistent ylim.
- Using tips, draw a lineplot of rolling mean (window=5) of total_bill over index; show ci=None and markers.
- From penguins, draw relplot(kind=”scatter”) with col=”sex” and row=”island”; share axes across facets.
- Using flights, draw a multi-series lineplot (one line per month) for a selected decade; add a legend with 12 entries.
- Create a scatterplot with a third quantitative variable mapped to color using hue= and palette=”viridis”; add a colorbar via hue_norm.
- On tips, draw two subplots: (A) scatterplot with hue=”smoker”, (B) lineplot of mean tip by day with hue=”smoker”; align titles.
- Using penguins, draw a relplot(kind=”line”) showing mean flipper_length_mm by species across islands (hue=”species”, col=”island”).
- With synthetic data containing time, group, and value, draw a lineplot with style=”group” and dashes=True.
- Using tips, draw a scatterplot of total_bill vs tip and encode party size with size=; adjust sizes and add alpha=.6.
- Build a relplot(kind=”line”) on flights with facet_kws={“sharey”: False}; annotate the max passenger point on each facet.
- Using penguins, create a scatterplot with hue=”species” and add sns.move_legend(ax, “upper left”, bbox_to_anchor=(1,1)) (or equivalent).
- From tips, draw a lineplot of mean total_bill by day with bootstrapped confidence intervals (n_boot higher than default).
- Using flights, create a relplot(kind=”line”) with row=”month” and col_wrap=4; use height=2.2 for compact panels.
- Build a scatterplot where outliers are annotated: compute z-scores for tip_pct and annotate points with |z|>2.
- Using a generated long-format time series (3 categories × 100 steps), draw a lineplot with hue and style; add markers every 10th point only.
- Create a relplot(kind=”scatter”) mapping hue and size to the same quantitative variable; explain the legend by enabling the size legend.
- Using penguins, draw a scatterplot and add sns.regplot (Matplotlib/seaborn compatible) on a second axes for comparison of trend depiction.
Advanced Questions
Time-Series Case Study (A):
From the flights dataset, engineer a tidy DataFrame with date (datetime), passengers, month, year, and decade.
Build arelplot(kind="line")
faceted byrow="decade"
, colored by month.
Unify y-limits, add a suptitle, and export to PNG and PDF.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.
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.Relational Facets Deep-Dive:
Create arelplot(kind="line")
of multiple groups across time withcol="region"
androw="product"
.
Synchronize color identity across all facets and add a single shared legend outside the grid.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.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.
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.Facet Grid Annotations:
With the flights dataset, build arelplot(kind="line")
faceted by month.
Annotate each facet with the year having maximum passengers and draw a horizontal reference line at the decade median.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.
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.