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()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.- 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
| Plot | Shows |
|---|---|
sns.histplot / kdeplot | distribution of one variable |
sns.boxplot / violinplot | spread & outliers across groups |
sns.scatterplot | relationship between two numbers |
sns.heatmap | a correlation matrix or grid |
sns.pairplot | every pair of variables at once |
sns.regplot), and smart colour palettes — with almost no code.- Seaborn = Matplotlib + beautiful defaults + one-line statistical plots.
- It reads DataFrames directly and handles categories with
hue,x,y. - Reach for
boxplot,scatterplot,heatmapandpairplotconstantly 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 zoomplotly.expresscreates 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.
| Your message is about… | Use |
|---|---|
| Comparing categories | Bar chart (horizontal if labels are long) |
| A trend over time | Line chart |
| Relationship between two numbers | Scatter plot |
| Distribution of one number | Histogram / boxplot |
| Parts of a whole (few categories) | Stacked bar (pie only for 2–3 slices) |
| A grid / matrix of values | Heatmap |
- 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.
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).
- 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.pyYou 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.
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.- Streamlit turns a Python script into an interactive web app — no front-end code.
st.metric,st.selectboxandst.plotly_chartbuild 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.
- Load a sales dataset and design the layout: a headline KPI row, a trend chart, and a breakdown chart.
- Add a headline
st.metricfor total sales (and maybe total orders and average order value). - Add at least two interactive filters with
st.selectbox/st.slider(e.g. region and date range). - Build a Plotly line chart for the sales trend over time and a bar chart for sales by category.
- Make every chart and KPI react to the filters (filter the DataFrame before plotting).
- Apply design principles: clear titles, sorted bars, one accent colour, value labels, readable fonts.
- Add a
requirements.txt(streamlit, pandas, plotly) and run locally withstreamlit run app.py. - 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.