Seaborn Assignment- 8

Advanced Customization

Basic Questions

  1. Create a lineplot and set x-axis to log scale (xscale=”log”); adjust x-limits to [1e-1, 1e2].
  2. Make a scatterplot and set y-axis to symlog with linthresh=1; add horizontal zero line.
  3. Draw a barplot and customize x tick locations to a fixed list with rotated labels (45°).
  4. Plot a histplot and set major ticks every 5 using Matplotlib’s MultipleLocator; show minor ticks too.
  5. Build a lineplot; set axis limits with set(xlim=(0, 50), ylim=(0, 100)) and add gridlines.
  6. Create a scatterplot; format y tick labels as percentages using FuncFormatter.
  7. Plot a correlation heatmap with sns.heatmap (annot=True, fmt=”.2f”) and a title via Matplotlib.
  8. Make a heatmap with a diverging palette centered at 0 using center=0.
  9. Create a heatmap and move the colorbar to the bottom, horizontal orientation with labeled ticks.
  10. Produce a masked upper-triangle heatmap (show only lower triangle) for a correlation matrix.
  11. Use sns.clustermap on a random matrix; keep default clustering and show colorbar.
  12. Re-create the clustermap with row_cluster=False (only columns clustered).
  13. Draw a clustermap with z-score normalization across rows (z_score=0).
  14. Create a clustermap and hide dendrogram colorbar while keeping the main colorbar.
  15. Combine: make a scatterplot (Seaborn) and then customize spines (hide top/right) with Matplotlib.
  16. Combine: draw a boxplot; add a Matplotlib annotation arrow pointing to the max median category.
  17. Create a heatmap and set a custom colorbar tick list (e.g., [-2, -1, 0, 1, 2]).
  18. Save any one figure as PNG (300 DPI) and SVG from the same script/cell.
  19. Save a clustermap as PDF with tight layout and a suptitle added via fig.suptitle.
  20. Create a lineplot and apply a global Seaborn theme (set_theme(style=”whitegrid”)), then export to PNG.

Intermediate Questions

  1. lineplot on long-tailed data; apply LogNorm to heatmap of residuals (use norm=LogNorm()) and add a matching colorbar.
  2. Build a scatterplot with logit y-scale (probabilities 0–1); set ticks to [0.01, 0.1, 0.5, 0.9, 0.99] with % formatter.
  3. Create a TwoSlopeNorm diverging heatmap centered at a custom value (e.g., center=50) with labeled colorbar.
  4. Draw two subplots: (A) lineplot, (B) scatterplot. Share the colorbar reflecting the same value range using ScalarMappable.
  5. Heatmap of a matrix with annotated values plus symbols (e.g., add “*” where value > threshold) using Matplotlib text overlays.
  6. Clustermap with custom linkage method (e.g., method=”average”, metric=”cosine”); add a figure-level title.
  7. Clustermap with row/col color labels (categorical colors aligned to metadata); include a legend explaining colors.
  8. Create a heatmap using a perceptually uniform colormap (e.g., “viridis”) and fixed vmin/vmax for comparability across runs.
  9. Draw relplot(kind=”line”); then manually control x tick frequency (every 3rd category) via FixedLocator.
  10. Combine: violinplot with custom facecolor alpha and Matplotlib hatch overlay for one category.
  11. Build a heatmap with square cells and thin gridlines (linewidths) for a tabular look; rotate both axes tick labels.
  12. Plot a heatmap where each cell shows two texts: value and a small subscript (e.g., sample size) using manual annotation.
  13. Compare three colorbars (left, right, bottom) in a 3-subplot figure of the same heatmap; ensure consistent ticks.
  14. Create a clustermap and suppress row labels but keep column labels; increase label font size and wrap long labels.
  15. Produce a lineplot; add secondary x-axis (twiny) with transformed units; align tick labels neatly.
  16. Combine: Seaborn scatterplot + Matplotlib inset axes showing a zoomed region of dense points; add rectangle on the main plot.
  17. Heatmap with BoundaryNorm (discrete color steps) and a colorbar with matching discrete ticks.
  18. Build a publication-ready figure setting key rcParams (fonts, axes linewidth, tick direction) before plotting a heatmap and a lineplot side-by-side.
  19. Export the same figure as PNG (300 DPI), SVG, and PDF; print file sizes and paths in the console/log.
  20. Create a themed figure: apply set_theme(style=”ticks”, context=”talk”, palette=”deep”); generate one heatmap and one scatter; despine and save.

Advanced Questions

  1. Axis Mastery Project: Create a 2×2 panel:

    • A: log–log lineplot with custom major/minor ticks

    • B: symlog scatterplot highlighting near-zero region

    • C: probability/logit plot (0–1) with formatted ticks

    • D: linear lineplot with broken x-axis (two inset axes)
      Add a shared style and export PNG + PDF.

  2. Heatmap Analytics Board: Build a 2×2 dashboard:

    • Corr heatmap (masked, annot, diverging)

    • Metric heatmap with TwoSlopeNorm

    • Discrete-step heatmap via BoundaryNorm

    • Tiny inset heatmap zoom
      Use one horizontal colorbar at the bottom controlling two panels, with consistent vmin/vmax.

  3. Clustermap With Metadata: Create a clustermap of standardized features (standard_scale=1). Attach row/column color bars for groups, add legends, adjust dendrogram linewidths, and export SVG.

  4. Advanced Colorbars: In a multi-axes figure (heatmap + scatter + line), implement three distinct colorbars (vertical, horizontal, inset), each with custom tick locators/formatters and titles.

  5. Annot & Guide Layer: On a correlation heatmap, overlay significance stars (p-values) and draw boxes around top-k absolute correlations. Include a caption panel via fig.text.

  6. Seaborn × Matplotlib Customization: Start with a Seaborn violinplot, then use Matplotlib to: recolor specific artists, add gradient-like hatch on one violin, annotate quartiles, and restyle spines/ticks.

  7. High-Res Publishing Pipeline: Define a helper export_figure(fig, basename) that saves PNG (300 DPI), SVG, and PDF with consistent metadata. Apply it to a 3-panel figure (heatmap, clustermap preview via ax.imshow, lineplot).

  8. Legend/Colorbar Unification: Create two heatmaps from related matrices with different scales. Normalize both to a shared Normalize so one shared colorbar explains both. Verify with matched tick labels.

  9. Categorical Heatmap Story: Convert a confusion matrix to rates. Plot a heatmap with percentage-formatted annotations, thresholds that change text color (black/white) for contrast, and a top-positioned colorbar.

  10. Final Expert Project: Compose a publication-ready page:

    • Header with title and subtitle

    • Left column: clustermap with metadata color bars

    • Right column: two stacked plots (correlation heatmap with stars; log-scale lineplot of a key metric)
      Apply unified typography (rcParams), consistent palette, neat tick labels, and export in PNG, SVG, and PDF.