Seaborn Assignment– 1
Seaborn Basics
Basic Questions
- Load the built-in tips dataset with sns.load_dataset; show the first 5 rows and plot total bill distribution using sns.histplot.
- Load the penguins dataset; drop rows with missing values and plot a scatter of flipper_length_mm vs bill_length_mm.
- From tips, create a bar plot of average tip by day using sns.barplot; show exact values as axis ticks.
- Using penguins, draw a categorical count plot (sns.countplot) for species.
- From tips, plot a boxplot of total_bill by day.
- Using tips, create a violin plot of total_bill by time (Lunch/Dinner).
- Load iris dataset; create a KDE plot (sns.kdeplot) of sepal_length.
- From iris, create a histogram with sns.histplot and overlay KDE.
- Using tips, draw a relational sns.scatterplot of total_bill vs tip colored by smoker.
- Using tips, plot a sns.lineplot of cumulative sum of total_bill over row index.
- From penguins, make a sns.stripplot of body_mass_g by species.
- Using penguins, create a sns.swarmplot of body_mass_g by sex.
- Load flights dataset and show a heatmap of passengers by month vs year with sns.heatmap.
- From tips, use sns.jointplot (kind=”scatter”) for total_bill and tip.
- With iris, plot pairwise relationships using sns.pairplot colored by species.
- Using any dataset, switch to Seaborn theme sns.set_theme(style=”whitegrid”) and re-plot a recent chart.
- From tips, create a sns.pointplot showing mean tip by day with confidence intervals.
- Using penguins, draw a sns.boxenplot for bill_depth_mm by species.
- Create a sns.countplot for tips[‘sex’] and annotate bar counts above each bar.
- Save one of your plots as PNG and SVG from the same figure object.
Intermediate Questions
- Load tips; create a sns.catplot(kind=”bar”) of mean total_bill by day, split by sex using hue.
- Using penguins, build a sns.relplot(kind=”scatter”) mapping size to body_mass_g and color to species.
- From flights, pivot to year×month matrix and plot a heatmap with custom colormap and labeled cells.
- With tips, compare sns.boxplot and sns.violinplot for total_bill by day in a 1×2 figure; keep a shared y-axis.
- Using iris, draw sns.jointplot(kind=”hex”) for sepal_length vs sepal_width.
- Load penguins; create a pairplot with different diag kind (kde) and off-diagonal kind (scatter).
- From tips, create sns.lmplot (scatter + regression) for total_bill vs tip with hue=”smoker”.
- Using tips, construct a FacetGrid with columns by time and rows by smoker, mapping a histplot of tip.
- Apply sns.set_style(“ticks”) and sns.set_context(“talk”); plot a scatterplot and compare typography vs default.
- Using penguins, create a catplot(kind=”swarm”) by species and sex; rotate x-tick labels for readability.
- From tips, compute a grouped Pandas DataFrame of mean/median total_bill by day; plot both as a layered lineplot.
- Using flights, plot a lineplot of passengers over years with style=”month” to get multiple monthly lines.
- With iris, build a displot (figure-level) showing histogram + KDE for petal_length with col=”species”.
- Switch palette globally to “mako” then draw a multi-series lineplot; verify color cycling.
- Create a custom palette from a list of hex colors and apply it to a barplot.
- Using tips, draw barplot with estimator=np.median and ci=None; annotate median values.
- From penguins, create two vertically stacked axes: top boxplot by species; bottom stripplot overlaid on same categories.
- Build a figure-level catplot(kind=”point”) with capsize=.2 and compare to an axes-level pointplot style on another axes.
- Using tips, demonstrate theme anatomy: set a figure title with fig.suptitle, axes titles with set_title, and apply margin adjustments to avoid overlap.
- 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
Figure/Theme Anatomy:
Create a publication-ready Seaborn theme usingset_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.Figure- vs Axes-level API:
Using the tips dataset, reproduce the same categorical plot once withcatplot
(figure-level) and once withboxplot
(axes-level) inside a custommatplotlib.figure.Figure
.
Discuss differences in layout control via code (suptitle, tight layout).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 × sexSwarm of raw points for the same categories below it
Align x categories between both plots.
Relational Faceting:
With the flights dataset, create arelplot(kind="line")
faceted byrow="month"
, colored by decade (derived column).
Add a legend and tidy tick formatting.Distribution Suite:
On a single figure with subplots, renderhistplot
,kdeplot
,ecdfplot
, andrugplot
for the same numeric series.
Unify x-limits and annotate mean/median lines.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.
Custom Palettes:
Create aListedColormap
-backed palette with 6 tones.
Apply it to three different plot types and include a legend color key subplot explaining the palette mapping.PairGrid Customization:
Build aPairGrid
on the iris dataset with custom mappings:Upper: scatter + regplot
Lower: filled kdeplot
Diagonal: histplot
Adjust despine and theme, then save as high-DPI.
Aesthetic Controls:
Usesns.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.End-to-End Report:
Load two datasets (tips, penguins). Create a 4-page PDF viaPdfPages
:
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.