Seaborn Assignment- 8
Advanced Customization
Basic Questions
- Create a lineplot and set x-axis to log scale (xscale=”log”); adjust x-limits to [1e-1, 1e2].
- Make a scatterplot and set y-axis to symlog with linthresh=1; add horizontal zero line.
- Draw a barplot and customize x tick locations to a fixed list with rotated labels (45°).
- Plot a histplot and set major ticks every 5 using Matplotlib’s MultipleLocator; show minor ticks too.
- Build a lineplot; set axis limits with set(xlim=(0, 50), ylim=(0, 100)) and add gridlines.
- Create a scatterplot; format y tick labels as percentages using FuncFormatter.
- Plot a correlation heatmap with sns.heatmap (annot=True, fmt=”.2f”) and a title via Matplotlib.
- Make a heatmap with a diverging palette centered at 0 using center=0.
- Create a heatmap and move the colorbar to the bottom, horizontal orientation with labeled ticks.
- Produce a masked upper-triangle heatmap (show only lower triangle) for a correlation matrix.
- Use sns.clustermap on a random matrix; keep default clustering and show colorbar.
- Re-create the clustermap with row_cluster=False (only columns clustered).
- Draw a clustermap with z-score normalization across rows (z_score=0).
- Create a clustermap and hide dendrogram colorbar while keeping the main colorbar.
- Combine: make a scatterplot (Seaborn) and then customize spines (hide top/right) with Matplotlib.
- Combine: draw a boxplot; add a Matplotlib annotation arrow pointing to the max median category.
- Create a heatmap and set a custom colorbar tick list (e.g., [-2, -1, 0, 1, 2]).
- Save any one figure as PNG (300 DPI) and SVG from the same script/cell.
- Save a clustermap as PDF with tight layout and a suptitle added via fig.suptitle.
- Create a lineplot and apply a global Seaborn theme (set_theme(style=”whitegrid”)), then export to PNG.
Intermediate Questions
- lineplot on long-tailed data; apply LogNorm to heatmap of residuals (use norm=LogNorm()) and add a matching colorbar.
- 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.
- Create a TwoSlopeNorm diverging heatmap centered at a custom value (e.g., center=50) with labeled colorbar.
- Draw two subplots: (A) lineplot, (B) scatterplot. Share the colorbar reflecting the same value range using ScalarMappable.
- Heatmap of a matrix with annotated values plus symbols (e.g., add “*” where value > threshold) using Matplotlib text overlays.
- Clustermap with custom linkage method (e.g., method=”average”, metric=”cosine”); add a figure-level title.
- Clustermap with row/col color labels (categorical colors aligned to metadata); include a legend explaining colors.
- Create a heatmap using a perceptually uniform colormap (e.g., “viridis”) and fixed vmin/vmax for comparability across runs.
- Draw relplot(kind=”line”); then manually control x tick frequency (every 3rd category) via FixedLocator.
- Combine: violinplot with custom facecolor alpha and Matplotlib hatch overlay for one category.
- Build a heatmap with square cells and thin gridlines (linewidths) for a tabular look; rotate both axes tick labels.
- Plot a heatmap where each cell shows two texts: value and a small subscript (e.g., sample size) using manual annotation.
- Compare three colorbars (left, right, bottom) in a 3-subplot figure of the same heatmap; ensure consistent ticks.
- Create a clustermap and suppress row labels but keep column labels; increase label font size and wrap long labels.
- Produce a lineplot; add secondary x-axis (twiny) with transformed units; align tick labels neatly.
- Combine: Seaborn scatterplot + Matplotlib inset axes showing a zoomed region of dense points; add rectangle on the main plot.
- Heatmap with BoundaryNorm (discrete color steps) and a colorbar with matching discrete ticks.
- Build a publication-ready figure setting key rcParams (fonts, axes linewidth, tick direction) before plotting a heatmap and a lineplot side-by-side.
- Export the same figure as PNG (300 DPI), SVG, and PDF; print file sizes and paths in the console/log.
- Create a themed figure: apply set_theme(style=”ticks”, context=”talk”, palette=”deep”); generate one heatmap and one scatter; despine and save.
Advanced Questions
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.
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.
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.
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.
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.
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.
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).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.
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.
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.