📊 Module 5

Data Visualisation

⏱ 14 hoursIntermediate6 topics
🎯 By the end: build clear charts with Matplotlib and Seaborn, create interactive figures with Plotly, choose the correct chart for any message, apply professional design principles, and deploy an interactive dashboard with Streamlit.

Great analysis is worthless if no one understands it. Visualisation is how insight travels from your screen into a decision-maker's head. This module teaches you the three core Python plotting libraries, how to pick the right chart, and how to design it so the message is unmistakable.

1Matplotlib fundamentals

Matplotlib is the foundation every Python chart is built on. The professional pattern is fig, ax = plt.subplots() — you get a figure (the canvas) and an axes (one plot) you control precisely.

import matplotlib.pyplot as plt

regions = ['North', 'East', 'West', 'South']
sales   = [5300, 4100, 3800, 2940]

fig, ax = plt.subplots(figsize=(7, 4))
ax.bar(regions, sales, color='#0e7490')
ax.set_title('Total sales by region')
ax.set_ylabel('Sales (Rs)')
ax.bar_label(ax.containers[0])     # value labels on bars
plt.tight_layout()
plt.show()
Total sales by region5300410038002940NorthEastWestSouth
The chart produced by the code above — clean bars, value labels, honest axis.
Anatomy worth knowing: a Figure holds one or more Axes; each Axes has a title, x/y labels, ticks and the plotted data. Master these and every other library makes sense.
Key points
  • Use fig, ax = plt.subplots() for full control over the figure and each plot.
  • Set title, axis labels and value labels — an unlabelled chart is useless.
  • Matplotlib is the base layer; Seaborn and pandas plotting sit on top of it.

2Seaborn: beautiful statistical plots

Seaborn wraps Matplotlib with gorgeous defaults and one-line statistical charts. It works directly with DataFrames and understands categories.

import seaborn as sns
import matplotlib.pyplot as plt
sns.set_theme(style='whitegrid')

# grouped bars: sales by region, split by quarter — one line
sns.barplot(data=df, x='region', y='sales', hue='quarter', errorbar=None)
plt.title('Quarterly sales by region')
plt.show()

The Seaborn staples

PlotShows
sns.histplot / kdeplotdistribution of one variable
sns.boxplot / violinplotspread & outliers across groups
sns.scatterplotrelationship between two numbers
sns.heatmapa correlation matrix or grid
sns.pairplotevery pair of variables at once
Why analysts love it: Seaborn adds the statistics for you — confidence intervals on bar charts, regression lines on scatters (sns.regplot), and smart colour palettes — with almost no code.
Key points
  • Seaborn = Matplotlib + beautiful defaults + one-line statistical plots.
  • It reads DataFrames directly and handles categories with hue, x, y.
  • Reach for boxplot, scatterplot, heatmap and pairplot constantly in EDA.

3Plotly: interactive charts

Static charts are great for reports; Plotly makes charts you can hover, zoom and filter — perfect for dashboards and exploration. plotly.express builds them in one line.

import plotly.express as px

fig = px.line(monthly, x='month', y='sales', markers=True,
              title='Monthly sales trend')
fig.update_traces(line_color='#0e7490')
fig.show()      # opens an interactive chart: hover for values, drag to zoom
Monthly sales trendJanFebMarAprMayJun
A Plotly line chart — in the browser you can hover each point and zoom in.
Right tool, right job: Matplotlib/Seaborn for static report figures and print; Plotly for interactive dashboards and anything embedded in a web app (which is exactly what we build in Streamlit next).
Key points
  • plotly.express creates interactive (hover/zoom/pan) charts in one line.
  • Interactivity suits dashboards and exploration; static libs suit printed reports.
  • Plotly figures embed cleanly in web apps like Streamlit.

4Choosing the right chart

The most common visualisation mistake is the wrong chart. Start from your message, then pick the chart that shows it most directly.

Barcompare categoriesLinetrend over timeScatterrelationshipPie / Donutparts of a whole
Match the chart to the message — comparison, trend, relationship or composition.
Your message is about…Use
Comparing categoriesBar chart (horizontal if labels are long)
A trend over timeLine chart
Relationship between two numbersScatter plot
Distribution of one numberHistogram / boxplot
Parts of a whole (few categories)Stacked bar (pie only for 2–3 slices)
A grid / matrix of valuesHeatmap
Avoid pie charts with many slices. Humans compare lengths far better than angles — a bar chart almost always beats a crowded pie.
Key points
  • Pick the chart from the message: comparison→bar, trend→line, relationship→scatter, distribution→histogram/box.
  • Use horizontal bars for long category names; reserve pies for 2–3 slices.
  • Heatmaps are ideal for matrices like correlations or category-by-category counts.

5Dashboard design & visual storytelling

A dashboard is not a pile of charts — it is an argument. Good design guides the eye from the headline number to the supporting detail.

Principles that make charts professional

  • One message per chart. If you cannot title it in a sentence, split it.
  • Maximise data-ink. Remove gridlines, borders and 3-D effects that carry no information.
  • Order with meaning. Sort bars by value, not alphabetically, unless order matters.
  • Highlight, do not decorate. Use one accent colour for the point you want noticed; grey the rest.
  • Label directly. Put values on bars and labels on lines instead of forcing a legend hunt.
  • Start bars at zero. A truncated axis exaggerates differences and misleads.
Accessibility is professional: do not rely on colour alone (add labels or patterns), keep text ≥ 12px, and check colour contrast. Use colour-blind-safe palettes (e.g. Seaborn's colorblind). An inclusive chart is a clearer chart.

Tell a story with structure

Lead with the headline KPI (one big number), then the trend (is it improving?), then the breakdown (where is it coming from?), and finish with the so-what (the recommendation).

Key points
  • One message per chart; remove non-data ink; sort by meaning.
  • Highlight the key point with one accent colour and direct labels; start bars at zero.
  • Design for accessibility — never colour alone, readable text, colour-blind-safe palettes.

6Interactive dashboards with Streamlit

Streamlit turns a Python script into a shareable web app — no HTML, CSS or JavaScript. It is the fastest way to put an interactive dashboard in front of stakeholders.

# app.py
import streamlit as st
import pandas as pd
import plotly.express as px

st.title('Sales Dashboard')
df = pd.read_csv('sales.csv')

# an interactive filter
region = st.selectbox('Region', ['All'] + sorted(df['region'].unique()))
if region != 'All':
    df = df[df['region'] == region]

# a headline KPI
total = df['sales'].sum()
st.metric('Total sales', '{:,.0f}'.format(total))

# a chart that reacts to the filter
by_region = df.groupby('region', as_index=False)['sales'].sum()
st.plotly_chart(px.bar(by_region, x='region', y='sales'))
pip install streamlit
streamlit run app.py
▶ Output
You can now view your Streamlit app in your browser.
Local URL: http://localhost:8501

Change the dropdown and the KPI and chart update instantly — a real, interactive product built from one file.

Ship it: push app.py and a requirements.txt to GitHub, then deploy free on Streamlit Community Cloud to get a public URL you can put on your CV.
Key points
  • Streamlit turns a Python script into an interactive web app — no front-end code.
  • st.metric, st.selectbox and st.plotly_chart build KPIs, filters and charts fast.
  • Run with streamlit run app.py; deploy free on Streamlit Community Cloud for a shareable URL.

★ Hands-on Project — Interactive Sales Dashboard

Build and deploy a multi-element interactive sales dashboard using Plotly and Streamlit — a portfolio centrepiece you can share with a live link.

  1. Load a sales dataset and design the layout: a headline KPI row, a trend chart, and a breakdown chart.
  2. Add a headline st.metric for total sales (and maybe total orders and average order value).
  3. Add at least two interactive filters with st.selectbox / st.slider (e.g. region and date range).
  4. Build a Plotly line chart for the sales trend over time and a bar chart for sales by category.
  5. Make every chart and KPI react to the filters (filter the DataFrame before plotting).
  6. Apply design principles: clear titles, sorted bars, one accent colour, value labels, readable fonts.
  7. Add a requirements.txt (streamlit, pandas, plotly) and run locally with streamlit run app.py.
  8. Deploy to Streamlit Community Cloud and add the live link + repo to your portfolio.

Ready to test yourself?

Take the module quiz. Score 70% or more to mark this module complete.

Start the quiz →

💡 Log in to save your progress and earn the certificate.