In short
Data visualisation is the practice of mapping numbers and categories to visual properties - position, length, angle, area, colour, shape - so that patterns, comparisons and outliers become visible far faster than from a table. For an AI and Data Science student it sits in the middle of the workflow: exploratory data analysis (EDA) before modelling, diagnostics during modelling, and reporting after it. It is examined in Python/data-analytics laboratory courses, in "Data Visualisation" or "Exploratory Data Analysis" papers under AICTE and CBCS curricula, and in GATE DA through questions on chart choice, reading distributions and interpreting correlation plots. Indian employers - TCS, Infosys, Wipro, Accenture, Deloitte, EXL, Mu Sigma, Fractal, Zomato, Flipkart, PhonePe, banks and the analytics cells of government departments - test matplotlib/seaborn fluency plus Power BI or Tableau in almost every data-analyst interview. Marks and offers are lost less on syntax than on choosing the wrong chart and misreading a scale.
Explained
Why visualise: perception and the grammar of graphics
- Visual encoding: a variable is assigned a visual channel. Accuracy of human judgement falls roughly in this order: position > length > angle/slope > area > volume > colour hue. So put the most important number on a common axis, not in a pie slice or bubble area.
- Pre-attentive attributes: colour, size, orientation and enclosure are noticed without conscious search - use exactly one of them to highlight, never three at once.
- Grammar of Graphics (Wilkinson; Wickham's ggplot2, Python's plotnine, Altair): every chart = data + aesthetic mappings (x, y, colour, size) + geometry (geom: bar, point, line) + statistical transform (count, mean, bin) + scale + coordinate system + facets. Learning this grammar makes any library predictable.
- Tufte's principles: maximise the data-ink ratio (ink showing data ÷ total ink), remove chartjunk (3-D effects, gradients, heavy gridlines), avoid the lie factor (size of effect shown ÷ size of effect in data; ideal = 1).
- Anscombe's quartet (4 datasets with identical mean, variance, correlation r = 0.816 and regression line but completely different shapes) and the Datasaurus dozen are the standard exam proof that summary statistics alone mislead - always plot.
- Stages: exploratory (fast, ugly, many plots, for yourself) → explanatory/presentation (one message, annotated, for others). Exam answers should name both.
Data types decide the chart
- Nominal (city, product), ordinal (grade, Likert), interval/ratio (temperature, income), temporal (date), geospatial (lat/long, PIN code, district).
- Univariate numeric: histogram (shape, modality), KDE (smoothed density, bandwidth chosen carefully), box plot (median, quartiles, outliers), violin (box + density), strip/swarm (every point, small n), ECDF (percentiles read directly, no binning choice).
- Univariate categorical: bar chart of counts (sorted by value, not alphabetically); pie only for 2-4 parts of a whole; treemap for nested shares; never a pie for trends.
- Bivariate: numeric-numeric → scatter (+ regression/LOWESS line, hexbin or 2-D density when overplotted); categorical-numeric → grouped box/violin/bar of means with error bars; categorical-categorical → grouped/stacked bar, mosaic plot, cross-tab heatmap.
- Multivariate: pair plot (scatter matrix), correlation heatmap, faceting/small multiples, bubble chart (size = third variable), parallel coordinates, radar (rarely justified), 2-D projections of PCA/t-SNE/UMAP for high-dimensional AI data.
- Time series: line chart (never bars for continuous time), area chart for totals, candlestick for OHLC finance data, seasonal subseries plot, ACF/PACF plots, rolling-mean overlays, log-scale y-axis for growth rates.
- Geospatial: choropleth (shade districts/states - always normalise by population or area), proportional-symbol map, dot-density; Indian work uses state/district shapefiles with GeoPandas, Folium or Power BI maps.
- Hierarchy/flow/relation: dendrogram, sunburst, Sankey diagram, network graph (NetworkX), funnel chart.
Matplotlib, seaborn, plotly - the Python stack
- Matplotlib is the base layer. Two interfaces: the pyplot state-machine (
plt.plot, quick) and the object-oriented API (fig, ax = plt.subplots(), thenax.plot) - the OO form is what interviews and production code expect. - Object hierarchy:
Figure(whole canvas,figsize,dpi) →Axes(one plot, has twoAxisobjects) →Artist(every line, patch, text).plt.savefig('f.png', dpi=300, bbox_inches='tight'); PNG/JPG are raster, SVG/PDF are vector - use vector for reports and print. - Common Axes methods:
set_title,set_xlabel,set_ylim,set_xscale('log'),legend,grid,annotate,twinx(second y-axis),axhline. Layout:plt.subplots(2, 2, figsize=(10,8), sharey=True)+fig.tight_layout()orconstrained_layout=True. - Backends:
Agg(file output, headless servers),TkAgg/QtAgg(windows),%matplotlib inline/widgetin Jupyter. Styles:plt.style.use('seaborn-v0_8-whitegrid'),rcParamsfor global defaults. - Seaborn is a statistical wrapper over matplotlib: tidy long-form DataFrame in, aggregation and confidence intervals computed for you. Figure-level functions (
relplot,displot,catplot,lmplot,jointplot,pairplot) own the whole figure and return a grid object (FacetGrid;JointGridforjointplot,PairGridforpairplot); axes-level functions (scatterplot,histplot,boxplot,heatmap,barplot,countplot) draw into an existingax. Mixing them up (catplot(..., ax=ax)) is a classic error - figure-level functions take noax. - pandas plotting:
df.plot(kind='bar'),df.plot.scatter,df.hist(),pd.plotting.scatter_matrix- matplotlib under the hood, fastest route during EDA. - Interactive: Plotly/Plotly Express (hover, zoom, HTML export), Bokeh, Altair (declarative Vega-Lite, grammar-of-graphics), Folium (Leaflet maps). Dashboards/apps: Streamlit, Dash, Gradio, Panel.
- Scale: Datashader/
hexbin/sampling for millions of points;plt.close(fig)in loops to avoid memory warnings.
BI tools and dashboards
- Power BI (dominant in Indian enterprises; Power Query for ETL, DAX measures, star-schema data model, slicers, bookmarks, row-level security, Service for sharing), Tableau (dimensions vs measures, shelves, calculated fields, LOD expressions, Tableau Public), Looker Studio (free, Google data), Qlik Sense, Metabase/Superset (open source), Excel (pivot charts, slicers, conditional formatting, sparklines) - still the most-used tool in Indian offices.
- Dashboard design: one question per view; most important KPI top-left (F/Z reading pattern); 5-9 tiles maximum; consistent colour meaning across tiles; filters visible; absolute numbers with the comparison baseline (target, last year); state "as on <date>" and the data source.
- Chart-to-tool mapping in interviews: "build it in Python" means reproducible, version-controlled, ML-adjacent; "build it in Power BI/Tableau" means refreshable, self-service, shared with business users.
Doing it right: scales, colour, annotation, accessibility, ethics
- Axis truncation: bar charts must start at zero (length encodes value); line charts of a narrow range may be truncated if the break is stated. Dual axes exaggerate or invent correlation - prefer indexing both series to 100 or two stacked panels.
- Log scale for multiplicative/exponential data (COVID curves, revenue growth, power-law distributions); state it on the axis label.
- Colour: sequential (light→dark, ordered magnitude), diverging (two hues around a meaningful midpoint, e.g. profit/loss, correlation ±1), qualitative (unordered categories, ≤ 8). Use perceptually uniform maps (viridis, cividis, magma); avoid jet/rainbow - it creates false edges. Around 8% of men worldwide (Indian studies report roughly 2-8%) have red-green colour blindness, so never encode by red-vs-green alone; add shape, label or texture.
- Normalisation: per-capita, per-area, rates and shares before comparing states or stores; show counts alongside percentages when bases differ.
- Uncertainty: show error bars/CI bands and say whether they are SD, SE or 95% CI; a bar of means with no spread hides everything.
- Ethics and law (India): the Digital Personal Data Protection Act, 2023 governs personal data - aggregate or mask before plotting, suppress small cells (a district count of 1-2 can re-identify), and never publish identifiable health or financial points. Public-sector reporting follows the National Data Sharing and Accessibility Policy (NDSAP, 2012) and data.gov.in open-data conventions; official statistics (MoSPI, NSO, Census, RBI DBIE) must be cited with release/vintage. Government web dashboards are expected to follow GIGW guidelines (accessibility, WCAG-aligned); financial charts in listed-company reporting follow SEBI disclosure requirements. Specific clauses and rule-making under the DPDP Act have been phased in, so check the current notification before relying on details.
Reading and interpreting charts (the exam skill)
- Box plot: box = Q1 to Q3 (IQR), line = median, whiskers = 1.5 × IQR convention (Tukey), points beyond = outliers. Whiskers are not min/max when outliers exist; the mean is not shown unless added.
- Histogram vs bar chart: histogram bins a continuous variable, bars touch, x is numeric and ordered, bin width changes the story (Sturges/Freedman-Diaconis rules); a bar chart shows distinct categories with gaps.
- Skew: right-skewed (long right tail) → mean > median; left-skewed → mean < median; bimodality signals a hidden subgroup - facet by it.
- Scatter: look for direction, strength, form (linear/curved), clusters, outliers, heteroscedasticity (fanning spread), Simpson's paradox (trend reverses within groups).
- Correlation heatmap: r near 0 can still mean a strong non-linear relation; correlation is not causation; mask the upper triangle for readability.
- ML diagnostics that are examined: confusion-matrix heatmap, ROC curve (TPR vs FPR, AUC), precision-recall curve (better for imbalanced data), learning curves (bias vs variance), residual plot (should be structureless), feature-importance/SHAP bar plot, elbow plot and silhouette plot for k-means.
Key points
- Visual encoding - mapping a variable to a channel; position and length are read most accurately, colour hue and area least.
- Grammar of Graphics - data + aesthetics + geometry + statistic + scale + coordinates + facets; the mental model behind ggplot2, Altair and seaborn.
- Data-ink ratio - share of ink that carries information; raise it by deleting chartjunk, not data.
- Lie factor - graphic effect ÷ data effect; must be ≈ 1. Truncated bar axes and 3-D pies inflate it.
- Anscombe's quartet - identical mean, variance and r = 0.816 across four very different scatter shapes; the case for plotting before computing.
- Histogram - distribution of one continuous variable; bin width (Sturges, Freedman-Diaconis) decides what you see.
- Box plot - five-number summary with 1.5 × IQR whiskers; best for comparing many groups' spread.
- Violin plot - box plot plus mirrored KDE; reveals bimodality a box plot hides.
- Scatter plot - two numeric variables; add hexbin/alpha when overplotted, LOWESS for form.
- Heatmap - matrix of values as colour; use a diverging map centred at 0 for correlations.
- Choropleth - region shaded by value; must be normalised (per capita/per km²) and use a sequential map.
- Small multiples / facets - same chart repeated per category; beats one crowded chart with ten colours.
- Figure vs Axes - matplotlib's canvas vs a single plot;
fig, ax = plt.subplots()is the professional idiom. - Figure-level vs axes-level seaborn -
relplot/catplot/displotown the figure (noaxargument);scatterplot/boxplot/histplotdraw into one. - Long (tidy) vs wide format - seaborn and Plotly Express expect long form: one row per observation, one column per variable.
- Sequential, diverging, qualitative palettes - for magnitude, deviation from a midpoint, and unordered categories respectively; viridis over jet.
- Accessibility - redundant encoding (shape + label + colour) for the ~8% of men with red-green colour deficiency; readable fonts, alt text, GIGW for government sites.
- DPDP Act, 2023 - plot aggregates, mask identifiers, suppress small cells; cite MoSPI/RBI vintage for official data.
Formulas and examples
Lie factor = (size of effect shown in graphic) ÷ (size of effect in data). Dimensionless; 1 = honest, >1 exaggerates.
Sturges' rule: k = 1 + log₂(n) bins; bin width h = (max − min)/k. n = number of observations, k rounded to an integer.
Freedman–Diaconis rule: h = 2 × IQR × n−1/3; k = ceil((max − min)/h). Robust to outliers; h in the data's own units.
Five-number summary / box plot: lower fence = Q1 − 1.5 × IQR, upper fence = Q3 + 1.5 × IQR, IQR = Q3 − Q1. Points outside the fences are plotted as outliers.
Pearson correlation (heatmaps): r = Σ(xᵢ − x̄)(yᵢ − ȳ) / √[Σ(xᵢ − x̄)² Σ(yᵢ − ȳ)²], −1 ≤ r ≤ +1, dimensionless.
Pie chart angle: θᵢ = 360° × (valueᵢ / Σ values); percentage = 100 × valueᵢ / Σ values.
Min–max scaling for bubble/colour: x′ = (x − min)/(max − min) ∈ [0,1]; for area-true bubbles, radius ∝ √value.
Aspect ratio of a saved figure = figsize_width × dpi : figsize_height × dpi pixels, e.g. (8,6) at 300 dpi = 2400 × 1800 px.
Example 1 - Bin count for a histogram of salaries. A placement cell has n = 1,000 CTC values, min = ₹2.4 lakh, max = ₹18.0 lakh, Q1 = ₹3.6 lakh, Q3 = ₹7.2 lakh.
- Sturges: k = 1 + log₂(1000) = 1 + 9.966 = 10.97 → 11 bins; h = (18.0 − 2.4)/11 = 15.6/11 = ₹1.42 lakh per bin.
- Freedman–Diaconis: IQR = 7.2 − 3.6 = ₹3.6 lakh; n1/3 = 10 exactly, so n−1/3 = 0.1; h = 2 × 3.6 × 0.1 = ₹0.72 lakh; k = ceil(15.6/0.72) = ceil(21.67) = 22 bins.
- FD gives narrower bins, which is right here: salary data is right-skewed with a long tail, and 11 wide bins would blur the dense low-CTC mass near ₹3-4 lakh. Report the mode band with the rule used.
Example 2 - Outlier fences and what the box plot shows. Monthly sales (₹ lakh) of 12 stores, sorted: 12, 14, 15, 18, 20, 21, 23, 25, 28, 30, 34, 72.
- Median = (21 + 23)/2 = ₹22 lakh. Lower half (12,14,15,18,20,21) → Q1 = (15 + 18)/2 = 16.5; upper half (23,25,28,30,34,72) → Q3 = (28 + 30)/2 = 29.
- IQR = 29 − 16.5 = 12.5. Lower fence = 16.5 − 18.75 = −2.25; upper fence = 29 + 18.75 = 47.75.
- 72 > 47.75 → plotted as an outlier; the upper whisker stops at the largest point ≤ 47.75, i.e. 34.
- Mean = 312/12 = ₹26 lakh > median ₹22 lakh → right skew. A bar chart of the mean alone would suggest a typical store earns ₹26 lakh; the box plot shows half the stores are below ₹22 lakh and one store distorts the average.
Example 3 - Lie factor of a truncated bar chart. Revenue rose from ₹100 crore to ₹110 crore (a true increase of 10%). The chart's y-axis starts at ₹95 crore, and the bars are drawn 5 mm and 15 mm tall.
- Graphic effect = (15 − 5)/5 = 2.00 = 200% apparent increase. Data effect = (110 − 100)/100 = 0.10 = 10%.
- Lie factor = 2.00/0.10 = 20 - the growth looks twenty times bigger than it is. Fix: start the bar axis at 0 (bars 100 mm and 110 mm → graphic effect 0.10, lie factor 1), or switch to a line/indexed chart and label the break.
Example 4 - Pie vs bar for market share. Shares: A 38%, B 31%, C 16%, D 9%, E 6%.
- Pie angles: A = 360 × 0.38 = 136.8°, B = 111.6°, C = 57.6°, D = 32.4°, E = 21.6° (sum 360.0°).
- A vs B differ by 25.2° of angle - hard to judge; as bars on a common axis the 7-point gap is read instantly. With 5 categories a sorted horizontal bar chart is the better answer; keep the pie only if the message is "A is about a third of the market".
Example 5 - Choropleth normalisation. Two states report EV registrations: State X 2,40,000 EVs, population 12 crore; State Y 90,000 EVs, population 1.5 crore.
- Raw counts: X looks 2.67× better and would be shaded darkest.
- Per lakh population: X = 240000/1200 = 200 per lakh; Y = 90000/150 = 600 per lakh - Y is 3× the adoption rate of X.
- A raw-count choropleth is effectively a population map. Always shade the rate and put the count in the tooltip.
| Need | Best chart | Avoid |
|---|---|---|
| Compare values across categories | Sorted horizontal bar | 3-D pie, radar |
| Parts of a whole (2-4 parts) | Pie / 100% stacked bar | Pie with 10 slices |
| Distribution of one numeric variable | Histogram, KDE, ECDF | Bar chart of raw values |
| Compare distributions of many groups | Box or violin plot | Mean-only bar chart |
| Relationship between two numerics | Scatter (+ LOWESS) | Dual-axis line |
| Trend over time | Line chart | Bars for continuous time |
| Value across regions | Normalised choropleth | Raw-count choropleth |
| Matrix of pairwise values | Diverging heatmap | Table of 100 numbers |
| Composition changing over time | Stacked area / 100% stacked | Many overlapping lines |
| Library | Strength | Weak point |
|---|---|---|
| Matplotlib | Total control, publication output, every format | Verbose; defaults look plain |
| Seaborn | Statistical charts, faceting, tidy-data API | Less control; figure-level/axes-level confusion |
| Plotly / Express | Interactive, hover, HTML & dashboards | Heavier output files; static export needs extra engine |
| Altair | Declarative grammar, clean syntax | Large datasets need special handling |
| Power BI / Tableau | Refreshable business dashboards, no code | Licensed; weaker for custom statistical plots |
import matplotlib.pyplot as plt, seaborn as sns, pandas as pd
df = pd.read_csv("placements.csv") # cols: branch, ctc_lakh, year, gender
fig, ax = plt.subplots(1, 2, figsize=(11, 4), constrained_layout=True)
# left: distribution with Freedman-Diaconis bins
sns.histplot(data=df, x="ctc_lakh", bins="fd", kde=True, ax=ax[0])
ax[0].set(title="CTC distribution", xlabel="CTC (Rs lakh)", ylabel="Students")
ax[0].axvline(df.ctc_lakh.median(), ls="--", color="black")
# right: compare branches - distribution, not just the mean
order = df.groupby("branch").ctc_lakh.median().sort_values(ascending=False).index
sns.boxplot(data=df, x="ctc_lakh", y="branch", order=order, ax=ax[1])
ax[1].set(title="CTC by branch (median-sorted)", xlabel="CTC (Rs lakh)", ylabel="")
fig.savefig("ctc.svg", bbox_inches="tight") # vector for the report
plt.close(fig)
# figure-level: small multiples - note NO ax= argument
g = sns.relplot(data=df, x="year", y="ctc_lakh", col="branch", hue="gender",
kind="line", errorbar=("ci", 95), col_wrap=3, height=2.8)
g.set_axis_labels("Year", "Mean CTC (Rs lakh)")
# correlation heatmap: diverging map centred at zero
num = df.select_dtypes("number")
sns.heatmap(num.corr(numeric_only=True), vmin=-1, vmax=1, center=0,
cmap="coolwarm", annot=True, fmt=".2f")
Where it is used
- IT services and consulting (TCS, Infosys, Wipro, Accenture, Deloitte, EY, Capgemini): Power BI/Tableau dashboards for client operations, SLA and finance reporting - the single largest employer of fresh "data analyst/BI developer" hires in India.
- Analytics firms and product companies (Mu Sigma, Fractal, EXL, Flipkart, Zomato, Swiggy, PhonePe, Razorpay, Ola): funnel, cohort and retention charts, A/B-test result plots, pricing and demand heatmaps in Python plus Looker/Tableau.
- BFSI and regulators: RBI's DBIE and bank MIS dashboards, credit-risk score distributions, NPA trend charts, fraud-pattern network graphs; SEBI-compliant disclosure charts in annual reports.
- Government and public health: data.gov.in and NITI Aayog indices, Census and NFHS district choropleths, MoSPI/NSO releases, IMD rainfall maps, electricity dashboards (POSOCO/Grid-India), Swachh Survekshan and NHM reporting - GIGW-compliant public dashboards.
- AI/ML engineering roles: TensorBoard and Weights & Biases training curves, confusion matrices, ROC/PR curves, SHAP and attention-map plots for model explainability - expected of every ML intern.
- Research, academia and journalism: matplotlib/SVG figures for papers and theses; data-journalism graphics at IndiaSpend, Hindu Data Point and Mint for election, budget and census stories.
Interview questions
- Q: When would you use a box plot instead of a histogram? A: When comparing the spread and median of many groups side by side, or when space is tight; a histogram shows one variable's shape in more detail, including multiple modes a box plot hides.
- Q: Why must a bar chart's y-axis start at zero but a line chart's need not? A: A bar encodes value by length, so truncating the axis distorts the length ratio; a line encodes change by slope, so a zoomed range is acceptable if the axis is labelled clearly.
- Q: What is Anscombe's quartet and what does it prove? A: Four datasets with the same mean, variance, correlation (0.816) and regression line but very different scatter shapes - it proves summary statistics cannot replace plotting.
- Q: Difference between figure-level and axes-level seaborn functions? A: Axes-level functions (
boxplot,scatterplot,histplot) draw into an existingax; figure-level ones (catplot,relplot,displot) create and own their own figure with faceting, so they accept noaxargument. - Q: Which colour map would you choose for a correlation matrix, and why? A: A diverging map centred at 0 (coolwarm, RdBu) with
vmin=-1, vmax=1, so the sign of the correlation is visible and equal magnitudes are equally intense. - Q: What is wrong with using a rainbow/jet colour map? A: It is not perceptually uniform - it creates false boundaries where values change smoothly and hides real differences elsewhere, and it fails in greyscale and for colour-blind viewers; viridis or cividis is the fix.
- Q: How do you plot 10 million points? A: Don't plot them individually - aggregate with a 2-D histogram/hexbin or Datashader, sample, or summarise by group; also set low alpha and rasterise the artists when exporting.
- Q: A manager wants sales and margin-% on one chart. What do you do? A: Avoid dual axes, which can manufacture apparent correlation; index both series to 100 at a base period, or use two vertically stacked panels sharing the x-axis.
- Q: What does Simpson's paradox look like in a scatter plot? A: The overall trend line slopes one way while the trend inside each group slopes the other; colouring or faceting by the confounding group reveals it.
- Q: How is a histogram different from a bar chart? A: A histogram bins a continuous variable - bars touch and the x-axis is a numeric scale; a bar chart compares discrete categories, so bars are separated and their order is arbitrary or sorted.
- Q: Which raster and vector formats do you save in, and when? A: PNG at 300 dpi for slides and the web, SVG or PDF for reports, papers and anything that will be zoomed or printed; JPEG is poor for charts because compression blurs text and lines.
- Q: What would you check before publishing a district-level map of patient counts? A: Normalise by population, use a sequential palette with sensible class breaks, suppress or merge very small cells to prevent re-identification under the DPDP Act, 2023, and cite the data source and date.
Common mistakes
- Using a pie chart for 8+ categories or for a trend over time, and 3-D effects that make slices unreadable.
- Truncating a bar chart's axis or adding a second y-axis, then drawing a conclusion from the exaggerated gap.
- Plotting raw counts on a choropleth instead of a per-capita or per-area rate, so the map just shows where people live.
- Reporting mean-only bar charts with no error bars or spread, hiding skew and outliers that a box or violin plot would expose.
- Passing
ax=to a figure-level seaborn function, or feeding wide data to a function that expects tidy long form. - Forgetting axis labels, units (₹ lakh vs ₹ crore), the legend, the title and the "as on" date - exam answers routinely lose marks here.
- Choosing bin width by default and then describing the distribution's shape, instead of checking it with the Freedman–Diaconis or Sturges rule.
- Reading box-plot whiskers as the minimum and maximum, and treating a near-zero correlation in a heatmap as "no relationship" without looking at the scatter.
Related topics
Python for data analysis: NumPy and pandas · Data cleaning and feature engineering · Statistics: descriptive measures and distributions · SQL queries and joins · Exploratory data analysis and hypothesis testing · Business intelligence and dashboarding (Power BI, Tableau)