Seaborn Assignment– 2

Styling & Themes

Basic Questions

  1. Re-plot a simple sns.lineplot under each built-in theme: “darkgrid”, “whitegrid”, “dark”, “white”, “ticks”; save five separate images.
  2. Apply sns.set_theme(style=”whitegrid”) and draw a barplot of any small DataFrame; compare to default.
  3. Use sns.set_style(“darkgrid”) and plot a scatterplot; turn off top/right spines with sns.despine().
  4. Change context to “talk” via sns.set_context(“talk”) and render a histplot; observe larger labels.
  5. Switch context to “paper” and redraw the same plot; export at 300 DPI.
  6. Set a qualitative palette “tab10” with sns.set_palette; draw a multi-series lineplot to verify cycling.
  7. Use a sequential palette “Blues” on a barplot with 8 bars; ensure bars progress light→dark.
  8. Use a diverging palette “RdBu” on a heatmap; set center=0 to show symmetric colors around zero.
  9. Plot a countplot with palette=”pastel” and rotate x-ticks by 45°.
  10. Create a boxplot and apply palette=”Set2″; add a title using Matplotlib.
  11. Draw a violinplot with palette=”rocket” (sequential) and set saturation=.9.
  12. Build a stripplot with palette=”Paired” and jitter enabled.
  13. Create a relplot(kind=”line”) and set style “ticks” plus sns.despine(offset=5).
  14. Set context “notebook” and linewidth=2 via sns.set_context; plot scatterplot with larger markers (s=100).
  15. Use sns.set_theme(style=”white”, palette=”deep”) and draw kdeplot with fill=True.
  16. Create a pairplot using a qualitative palette; save as SVG.
  17. Set palette=”mako” and draw a catplot(kind=”point”) with confidence intervals.
  18. Plot a histplot with KDE using “crest” palette; set figure facecolor to light gray via Matplotlib.
  19. Use sns.set_style to hide gridlines; draw a lineplot and confirm plain background.
  20. Save any plot to PDF and PNG from the same figure; compare file sizes printed in console.

Intermediate Questions

  1. Build a custom qualitative palette from five hex colors using sns.color_palette([…]); apply to a barplot.
  2. Create a sequential palette with sns.light_palette(“#1f77b4”, n_colors=7); apply to a heatmap with colorbar.
  3. Create a diverging palette with sns.diverging_palette(220, 20, n=9, center=”light”); apply to clustermap.
  4. Construct a perceptually uniform palette using “viridis” and apply to lineplot with 6 series.
  5. Use sns.set_context(“poster”, font_scale=1.2) and draw a dashboard-style figure with two axes; ensure readable typography.
  6. Modify style parameters with sns.set_style({“axes.facecolor”: “.95”, “grid.color”: “.8”}); draw boxplot.
  7. Mix Matplotlib rcParams (e.g., axes.titleweight, axes.labelsize) with sns.set_theme; plot scatterplot to verify.
  8. Create a reusable function apply_publication_theme() that sets Seaborn style, context, palette, and Matplotlib rcParams; call it before plotting a lineplot.
  9. Create a palette using sns.cubehelix_palette(start=.5, rot=-.75, as_cmap=True); apply to kdeplot(fill=True).
  10. Generate a PairGrid; set a global palette and style, then map scatter on upper, kde on lower, hist on diag.
  11. Draw barplot and add exact value labels; ensure palette has sufficient contrast on a whitegrid background.
  12. Use sns.set_palette(sns.color_palette(“husl”, 8)) to style an 8-category countplot.
  13. Apply “ticks” style; then remove only the right spine and keep gridlines; render lineplot.
  14. Compose a figure with three subplots; apply different contexts (paper, talk, poster) per-axes using sns.set_context in a context manager (with block).
  15. Build a custom .mplstyle that adjusts font, linewidth, and tick size; load it via plt.style.use together with sns.set_theme; plot violinplot.
  16. Show palette swatches of your custom palette using sns.palplot; save as a legend image for your brand kit.
  17. Draw a heatmap with TwoSlopeNorm centered at 0 and a diverging palette; add a caption via fig.text.
  18. Create a relplot(kind=”line”) faceted by category; apply a single palette globally and verify consistent colors across facets.
  19. Implement a grayscale theme using sns.set_theme(style=”white”) and sns.set_palette(“gray”); draw barplot and kdeplot in one figure.
  20. Programmatically switch between three named palettes for the same lineplot and save each variant to disk.

Advanced Questions

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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.
  6. 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.
  7. 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.
  8. 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.
  9. 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.
  10. 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.