💳
Persona
Karthik — Senior Analyst, Paytm Bengaluru

You're building a weekly insights deck for the payments leadership team. The default Excel charts look dated. You need to produce publication-ready visuals fast—countplots, distributions, heatmaps—and ship them as SVG or PNG for reports. You also want to explore payment trends interactively before you finalize them.

3,000
Transactions
5
Cities
54.8%
UPI Share

Why Seaborn? Opinionated defaults that save hours

Matplotlib is the foundation—it's powerful but verbose. Seaborn sits on top and gives you statistical graphics with a single function call. The colours work, the fonts breathe, the proportions feel right.

Seaborn

  • Beautiful defaults (no tweaking axis labels)
  • Built-in statistical plots (countplot, boxplot, heatmap)
  • Easy multi-variable relationships (FacetGrid)
  • Integrates seamlessly with pandas
  • SVG/PNG export for reports

Plotly

  • Interactive (hover, zoom, click legends)
  • Dashboards in Streamlit or Dash
  • 3D charts and animations
  • Great for exploration & demos
  • HTML export (can't use in PDF reports)

The pattern: Use Seaborn for static reports, Plotly for interactive dashboards. Sometimes you'll use both in the same workflow.

Countplot: Category frequencies at a glance

Payment methods aren't equally distributed. UPI dominates. A countplot shows the picture in one chart:

Distribution of payment methods across 3,000 transactions
Seaborn countplot of payment categories
Key insight: UPI accounts for 54.8% of all transactions (1,643 out of 3,000). Wallet is second at 25.0%. This drives product strategy: invest in UPI optimization first.
Python · countplot.py

Boxplot: Distributions across groups

Amounts vary wildly by payment method. A boxplot shows median, quartiles, and outliers side-by-side:

Amount distribution by payment method (log scale to handle range)
Seaborn boxplot of amounts by category
What you see: The box is the IQR (25th to 75th percentile), the line inside is the median, whiskers extend to 1.5× IQR, and dots are outliers. UPI has a tighter distribution (most transactions 200–500), while CreditCard spreads wider.
Python · boxplot.py

Heatmap: Two-way relationships

How do payment methods vary by age group? A heatmap shows the intersection counts as color intensity:

Payment method × age group transaction counts
Seaborn heatmap of category by age band
Pattern: Younger users (18–25) skew UPI; older cohorts (46+) are more balanced. This informs marketing and onboarding flows.
Python · heatmap.py

FacetGrid: Small multiples for clarity

Same chart, separate panels for each city. FacetGrid repeats a plot across subgroups:

Amount distribution (histogram) for each city
Seaborn FacetGrid of amount by city
Benefit: At a glance, you see that Mumbai and Delhi have similar distributions, while smaller metros (Pune) show slightly lower medians. No need for separate notebooks per city.
Python · facetgrid.py

When to use Plotly: Interactive exploration

Plotly shines when you need interactivity. Hover to see exact values, click legends to toggle series, zoom into clusters. Perfect for dashboards and live demos.

Same scatter chart, rendered as static (Seaborn style)
Static scatter plot of amounts
Python · plotly_basic.py

Exporting to SVG & PNG for reports

Both libraries ship static formats. For Seaborn (matplotlib), use savefig() with format. For Plotly, use kaleido (requires headless browser):

Python · export_seaborn.py
Python · export_plotly.py
Pro tip: SVG files are resolution-independent and editable in Illustrator/Inkscape. PNG is smaller and embeds directly in Word. Use SVG for archival and creative adjustments, PNG for web.

Common pitfalls & how to avoid them

1. Forgetting to scale log axes for right-skewed data

Transaction amounts are lognormal. A linear y-axis squashes most data near zero. Always use plt.yscale('log') or fig.update_yaxes(type='log').

2. Too many colours in a heatmap

Sequential palettes (single-hue gradients) work best. Avoid rainbow or diverging colormaps unless you're showing negative correlations.

3. Forgetting to use tight_layout()

Labels often get cut off at export. Always call plt.tight_layout() before savefig().

4. Overloading FacetGrid with too many subplots

A 5×5 grid of histograms becomes unreadable. Stick to 6–12 subplots max. If you have more categories, use colour or interactivity (Plotly) instead.

5. Trying to use Plotly HTML in a PDF report

Plotly HTML files don't embed in PDFs. Export to PNG or SVG if the output must be static.

Quick reference: Seaborn vs. Plotly

Use Case Seaborn Plotly
Statistical plots (countplot, boxplot, heatmap) ✓ Native functions ⚠ Requires custom code
Static reports (PDF, Word) ✓ SVG/PNG export ⚠ Needs kaleido
Interactive dashboards ✗ Static only ✓ Native HTML
Exploration in Jupyter ✓ Fast iteration ✓ Great hover info
Small file size ✓ SVG compact ⚠ HTML can be large
Learning curve ✓ Gentle (if you know matplotlib) ⚠ Steeper (different API)
📥
Download the dataset
paytm_txns_sample.csv — 3,000 transactions from Paytm India
1/3
Test your understanding
Which library should you use to create a boxplot showing transaction amounts grouped by payment method?
Seaborn — sns.boxplot() is built in
Plotly — it has better interactivity
Matplotlib — it's the most flexible
Pandas — use df.plot()
Why would you use a log scale on the y-axis for transaction amounts?
To make the chart smaller
Because amounts are right-skewed (long tail), log scale shows the distribution shape better
Because it's always best practice
To hide outliers
You need to produce a chart for a Word document. You have both a Seaborn and a Plotly version. Which should you export?
Seaborn as SVG or PNG — static formats embed in documents
Plotly HTML — it's more modern
Either one — Word supports both
Plotly PNG exported via kaleido
Africa & India's Best AI Academy
🤖 AI-first 🎓 Placement Assistance

Ready to let stakeholders click?

Join the Best AI Program: The AI-Era Analyst — 5 months, fully online, with placement assistance. Week 1 is free.

Explore The AI-Era Analyst →