Data Visualisation#
Making Numbers Speak Louder Than Words
“If data were a novel, visualization would be the movie adaptation everyone actually watches.”
Welcome, Data Picasso! 🧑🎨 You’ve cleaned, wrangled, and explored your data. Now it’s time to make it shine — not with glitter, but with charts that make business people go “Ooooh!”
🧠 Why Visualization Matters#
In business, a great chart can:
Save you 10 slides of explanation 📊
Convince your boss faster than a 50-page report 💼
Expose hidden insights (or at least hide your messy code 😉)
💬 “Never underestimate a well-placed bar chart — it can justify your annual budget.”
🧰 Prerequisite#
If you’re new to Python plotting libraries, check out my other book: 👉 📘 Programming for Business
🖼️ The Visualization Toolkit#
Let’s meet your artistic weapons of choice:
Library |
Best For |
Why You’ll Love It |
|---|---|---|
Matplotlib |
Custom static plots |
Like Excel, but on steroids |
Seaborn |
Quick, pretty statistical charts |
Beautiful defaults, less crying |
Plotly |
Interactive dashboards |
Drag, zoom, impress investors |
Altair |
Declarative visualization |
Concise, elegant, and logic-based |
🎬 Step 1. Setting the Stage#
💬 “Always set a nice style — even your plots deserve good fashion.”
📈 Step 2. Bar Charts — The Office Favorite#
When in doubt, use a bar chart. They’re simple, effective, and universally loved by PowerPoint warriors.
🗣️ “This chart says more about your market than 5 strategy meetings.”
📊 Step 3. Line Charts — Time’s Storytellers#
Use line plots to show trends, growth, and seasonal effects.
💡 “A line going up? You’re a genius. A line going down? You’re an analyst who ‘found optimization opportunities.’”
🍩 Step 4. Pie Charts — Only for Special Occasions#
Use sparingly. One pie chart per quarter is the professional limit.
💬 “Pie charts are like desserts — lovely in small doses, disastrous if overused.”
🔁 Step 5. Scatter Plots — The Relationship Therapist#
Show how two variables interact — like marketing spend and sales.
💬 “If there’s an upward trend — congrats, your marketing is actually doing something!”
🧩 Step 6. Heatmaps — The Data Spa#
Relax your brain and let colors show correlations.
💡 “Red means love, blue means distance — just like business meetings.”
🧠 Step 7. Pairplots — The Multiverse of Data#
A full relationship matrix — because who doesn’t love chaos?
💬 “This is the Tinder of plots — every variable gets to date every other one.”
📦 Step 8. Business Dashboard Preview#
Turn your visuals into interactive gold:
💡 “Plotly charts are like Instagram filters — they make your data instantly more likable.”
🧪 Practice Lab — “Visualize or Vanish!”#
Use the dataset company_sales.csv and visualize:
Sales by product category
Sales trend over time
Profit vs marketing spend
Region-wise revenue contribution
A correlation heatmap between numerical features
🎯 Bonus: Create one chart that could appear in your company’s annual report (without getting you fired).
🧭 Recap#
Visualization |
Use Case |
Library |
|---|---|---|
Bar Chart |
Compare categories |
Seaborn / Matplotlib |
Line Chart |
Show trends over time |
Seaborn |
Scatter Plot |
Relationships |
Seaborn |
Heatmap |
Correlation matrix |
Seaborn |
Pie Chart |
Share distribution |
Matplotlib |
Interactive Dash |
Exploration |
Plotly |
🎁 Quick Pro Tips#
Don’t overload charts — your data deserves breathing space 🧘
Color with purpose — not all rainbows are business-friendly 🌈
Always add titles and labels 📋
Save your plots as
.pngfor reports 📸
💬 “Because nothing says ‘professional’ like a crisp 300 DPI chart.”
🔜 Next Stop#
👉 Business Dashboards You’ll learn how to stitch your visual masterpieces together — to make dashboards so sleek that executives might finally stop asking for Excel sheets.
Histograms, Box Plots, Scatter Plots, Pair Plots, Heatmaps (with customization)#
🎯 Learning Objectives#
By the end of this section, students should be able to:
Create basic visualizations using matplotlib and seaborn.
Understand the purpose and interpretation of each plot type.
Customize visual elements — titles, labels, legends, colors, and layout.
Use visualizations to gain insights into data distribution and relationships.
🧩 1. Setup and Dummy Dataset#
We’ll use a small artificial dataset that mimics a business scenario (sales, customers, and marketing).
📊 2. Histogram — Understanding Data Distribution#
Histograms help visualize the distribution (spread and skewness) of numerical variables.
✅ Interpretation:
Check if sales are normally distributed or skewed.
Identify outliers or irregular peaks.
📦 3. Box Plot — Spotting Outliers#
Box plots show median, quartiles, and outliers clearly.
✅ Interpretation:
Regions with higher medians = better profit performance.
Dots outside whiskers = outliers.
⚪ 4. Scatter Plot — Relationship Between Two Variables#
Useful to analyze correlation and patterns between numeric variables.
✅ Interpretation:
Observe if higher marketing spend leads to higher sales.
Differentiate regional trends.
🧩 5. Pair Plot — Multiple Variable Relationships#
Pair plots show scatter plots between every numeric pair and histograms on the diagonal.
✅ Interpretation:
Detect linear/nonlinear relationships.
Check for correlations or clusters by region.
🔥 6. Heatmap — Correlation Between Variables#
Heatmaps visualize how strongly numerical variables are correlated.
✅ Interpretation:
Values near +1 → strong positive correlation.
Values near -1 → strong negative correlation.
Helps detect multicollinearity.
🎨 7. Customizing Plots (Titles, Labels, Legends, Styles)#
You can globally customize appearance using plt.rcParams or sns.set_theme().
Example:
Customization Options:#
Element |
Function |
|---|---|
|
Adds plot title |
|
Adds axis labels |
|
Shows/hides legend |
|
Enables grid lines |
|
Changes overall style (e.g., “ggplot”, “seaborn”) |
|
Sets color scheme in seaborn plots |
🧠 8. Key Takeaways#
Plot Type |
Purpose |
Example Use Case |
|---|---|---|
Histogram |
Distribution of single variable |
Sales amount spread |
Box Plot |
Median, spread, and outliers |
Profit by region |
Scatter Plot |
Relationship between two variables |
Sales vs marketing spend |
Pair Plot |
All pairwise relationships |
Sales, profit, and spend |
Heatmap |
Correlation matrix visualization |
Detect related metrics |
✅ 9. Practical Exercise#
Load any CSV dataset (e.g., from Kaggle or your own sales data).
Create at least one of each type of plot.
Add proper titles, labels, and legends.
Write one-line insights below each plot.
Using Plotly for interactive charts#
Combining multiple visuals into simple dashboards#
🎯 Learning Objectives#
By the end of this section, students will be able to:
Create interactive visualizations using Plotly.
Understand how to use hover, zoom, and filter features.
Combine multiple Plotly charts into a simple interactive dashboard layout.
Present data insights dynamically — ideal for business analytics and storytelling.
⚙️ 1. Setup#
We’ll use the plotly library (specifically plotly.express and plotly.graph_objects).
📈 2. Interactive Line Chart (Sales Trend Over Time)#
✅ Highlights:
Hover over data points to see exact values.
Zoom in/out with drag.
Pan across time series easily.
Clean, publication-ready visuals with one line of code.
📊 3. Interactive Bar Chart (Profit by Region)#
✅ Highlights:
Hover shows data for each region.
Bars are color-coded automatically.
Perfect for category comparisons.
⚪ 4. Interactive Scatter Plot (Sales vs Profit)#
✅ Highlights:
Hover reveals Month, Sales, Profit, Region.
Circle size encodes Profit value.
Visually identifies strong-performing regions.
🧱 6. Combining Multiple Visuals into a Dashboard#
You can combine multiple Plotly figures into one interactive dashboard layout using make_subplots() from plotly.subplots.
✅ Dashboard Features:
All visuals are interactive — zoom, hover, click.
Unified look with a single white theme.
Ideal for JupyterBook, JupyterLab, or Streamlit integration.
⚡ 7. Business Insights from Dashboard#
Sales Trend: Observe which months have high or low sales.
Profit by Region: Identify the most profitable regions.
Sales vs Profit: See whether sales strongly relate to profits.
Sales Share: Understand contribution of each region to total sales.
🎨 8. Enhancements (Optional)#
You can further:
Add dropdown filters using
plotly.graph_objectsandupdatemenus.Export as HTML using
fig.write_html("dashboard.html").Embed into websites or JupyterBook using:
```{raw} html <iframe src="dashboard.html" width="100%" height="800"></iframe>
🧠 9. Key Takeaways#
Concept |
Description |
|---|---|
Plotly Express |
Easiest way to create interactive charts |
Hover & Zoom |
Built-in, no extra coding |
Subplots |
Combine visuals into dashboards |
Export |
Save and embed as standalone HTML |
Ideal For |
Business dashboards, storytelling, data apps |
✅ 10. Practical Exercises#
Create an interactive line chart showing monthly revenue for multiple regions.
Add a dropdown menu to switch between “Sales” and “Profit”.
Combine 3 Plotly charts into one dashboard.
Save your dashboard as
business_dashboard.html.Embed it in your JupyterBook under a section called Interactive Insights.
# Your code here