Seaborn Assignment– 2
Styling & Themes
Basic Questions
- Re-plot a simple sns.lineplot under each built-in theme: “darkgrid”, “whitegrid”, “dark”, “white”, “ticks”; save five separate images.
- Apply sns.set_theme(style=”whitegrid”) and draw a barplot of any small DataFrame; compare to default.
- Use sns.set_style(“darkgrid”) and plot a scatterplot; turn off top/right spines with sns.despine().
- Change context to “talk” via sns.set_context(“talk”) and render a histplot; observe larger labels.
- Switch context to “paper” and redraw the same plot; export at 300 DPI.
- Set a qualitative palette “tab10” with sns.set_palette; draw a multi-series lineplot to verify cycling.
- Use a sequential palette “Blues” on a barplot with 8 bars; ensure bars progress light→dark.
- Use a diverging palette “RdBu” on a heatmap; set center=0 to show symmetric colors around zero.
- Plot a countplot with palette=”pastel” and rotate x-ticks by 45°.
- Create a boxplot and apply palette=”Set2″; add a title using Matplotlib.
- Draw a violinplot with palette=”rocket” (sequential) and set saturation=.9.
- Build a stripplot with palette=”Paired” and jitter enabled.
- Create a relplot(kind=”line”) and set style “ticks” plus sns.despine(offset=5).
- Set context “notebook” and linewidth=2 via sns.set_context; plot scatterplot with larger markers (s=100).
- Use sns.set_theme(style=”white”, palette=”deep”) and draw kdeplot with fill=True.
- Create a pairplot using a qualitative palette; save as SVG.
- Set palette=”mako” and draw a catplot(kind=”point”) with confidence intervals.
- Plot a histplot with KDE using “crest” palette; set figure facecolor to light gray via Matplotlib.
- Use sns.set_style to hide gridlines; draw a lineplot and confirm plain background.
- Save any plot to PDF and PNG from the same figure; compare file sizes printed in console.
Intermediate Questions
- Build a custom qualitative palette from five hex colors using sns.color_palette([…]); apply to a barplot.
- Create a sequential palette with sns.light_palette(“#1f77b4”, n_colors=7); apply to a heatmap with colorbar.
- Create a diverging palette with sns.diverging_palette(220, 20, n=9, center=”light”); apply to clustermap.
- Construct a perceptually uniform palette using “viridis” and apply to lineplot with 6 series.
- Use sns.set_context(“poster”, font_scale=1.2) and draw a dashboard-style figure with two axes; ensure readable typography.
- Modify style parameters with sns.set_style({“axes.facecolor”: “.95”, “grid.color”: “.8”}); draw boxplot.
- Mix Matplotlib rcParams (e.g., axes.titleweight, axes.labelsize) with sns.set_theme; plot scatterplot to verify.
- Create a reusable function apply_publication_theme() that sets Seaborn style, context, palette, and Matplotlib rcParams; call it before plotting a lineplot.
- Create a palette using sns.cubehelix_palette(start=.5, rot=-.75, as_cmap=True); apply to kdeplot(fill=True).
- Generate a PairGrid; set a global palette and style, then map scatter on upper, kde on lower, hist on diag.
- Draw barplot and add exact value labels; ensure palette has sufficient contrast on a whitegrid background.
- Use sns.set_palette(sns.color_palette(“husl”, 8)) to style an 8-category countplot.
- Apply “ticks” style; then remove only the right spine and keep gridlines; render lineplot.
- Compose a figure with three subplots; apply different contexts (paper, talk, poster) per-axes using sns.set_context in a context manager (with block).
- Build a custom .mplstyle that adjusts font, linewidth, and tick size; load it via plt.style.use together with sns.set_theme; plot violinplot.
- Show palette swatches of your custom palette using sns.palplot; save as a legend image for your brand kit.
- Draw a heatmap with TwoSlopeNorm centered at 0 and a diverging palette; add a caption via fig.text.
- Create a relplot(kind=”line”) faceted by category; apply a single palette globally and verify consistent colors across facets.
- Implement a grayscale theme using sns.set_theme(style=”white”) and sns.set_palette(“gray”); draw barplot and kdeplot in one figure.
- Programmatically switch between three named palettes for the same lineplot and save each variant to disk.
Advanced Questions
- Publishing Theme Kit: Define a full publishing-ready theme function that sets Seaborn context/style/palette and Matplotlib rcParams (fonts, linewidths, tick directions, grid alpha). Render a 2×2 plot suite (categorical, relational, distribution, heatmap) with one suptitle; export PNG (300 DPI) and PDF.
- Brand Palette System: Create a brand palette (primary, secondary, accent, neutrals). Apply it consistently across barplot, lineplot, and scatterplot; include a legend subplot that displays the palette swatches with hex codes.
- Perceptual Audit: Build the same multi-series lineplot with three palette families—qualitative, sequential, diverging—and add a panel that explains when to use each; export to SVG and inspect color continuity.
- Accessibility Check: Generate a palette optimized for color-vision deficiencies using sns.color_palette(“colorblind”) and compare against a default palette on identical barplots; annotate bars with values to ensure readability.
- Dual-Stack Styling: Apply a Matplotlib .mplstyle for baseline typography and a Seaborn theme for grids/palettes; render a dashboard (3 subplots). Verify no conflicts by printing key rcParams before/after.
- Dynamic Context Manager: Create a context-manager class that temporarily sets Seaborn style/palette/context for a figure and reverts afterward; use it to produce two differently styled figures in one script.
- Palette From Data: Derive a custom palette from data quantiles (e.g., low→high mapped to a sequential palette). Use it to color a stripplot where each point’s color corresponds to its quantile bin; include a color key.
- Diverging Theme for Signed Data: Build a diverging theme with custom center and apply it to a heatmap of correlations; ensure symmetric color limits and labeled colorbar; save at 600 DPI.
- LaTeX/Pgf Integration: Configure PGF backend, set serif fonts via rcParams, apply Seaborn style “whitegrid”, and create a figure with math labels; export .pgf and demonstrate consistent look in a compiled LaTeX document.
- Style QA Pipeline: For a given dataset, render the same FacetGrid under four styles (darkgrid/whitegrid/dark/white). Save all as PNG; then write a small function that checks image file sizes and logs the active style and file size to a CSV for documentation.