Data Visualization#
Matplotlib + Seaborn + Plotly = $70K/month reporting 1 chart = 1000 Excel cells β Instant decisions
Google/Amazon = 100% visual analytics
π― Visualization = Executive Decision Weapon#
Chart Type |
Business Question |
Replaces |
C-Suite Value |
|---|---|---|---|
Line |
Sales trends |
50 Excel lines |
Growth story |
Bar |
Product comparison |
Manual tables |
Top performers |
Scatter |
Correlation |
Complex formulas |
ROI insights |
Heatmap |
Performance matrix |
100+ cells |
Weakest links |
Dashboard |
ALL ABOVE |
PowerPoint decks |
$1M decisions |
π Step 1: Matplotlib = Custom Analytics (Run this!)#
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
# REAL BUSINESS DATA
months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun']
sales = [25000, 32000, 28000, 45000, 52000, 61000]
profit_margin = [0.25, 0.28, 0.22, 0.32, 0.35, 0.38]
# 1. LINE CHART: Sales growth
plt.figure(figsize=(12, 8))
plt.plot(months, sales, marker='o', linewidth=3, markersize=10, color='#2E86AB')
plt.title('π° Monthly Sales Growth', fontsize=16, fontweight='bold')
plt.ylabel('Sales ($)', fontsize=12)
plt.xlabel('Month', fontsize=12)
plt.grid(True, alpha=0.3)
plt.xticks(rotation=45)
plt.tight_layout()
plt.show()
# 2. BAR CHART: Profit by month
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(15, 6))
ax1.bar(months, sales, color='#A23B72', alpha=0.8)
ax1.set_title('Sales by Month', fontweight='bold')
ax1.set_ylabel('Sales ($)')
ax1.tick_params(axis='x', rotation=45)
profits = [s * m for s, m in zip(sales, profit_margin)]
ax2.bar(months, profits, color='#F18F01', alpha=0.8)
ax2.set_title('Profits by Month', fontweight='bold')
ax2.set_ylabel('Profit ($)')
ax2.tick_params(axis='x', rotation=45)
plt.tight_layout()
plt.show()
π₯ Step 2: Seaborn = Publication-Quality Statistical Plots#
# !pip install seaborn # Run once!
import seaborn as sns
# REAL BUSINESS DATAFRAME
data = {
'Product': ['Laptop', 'Phone', 'Tablet', 'Monitor', 'Keyboard'],
'Sales': [45000, 32000, 18000, 25000, 8000],
'Margin': [0.32, 0.28, 0.22, 0.25, 0.18],
'Region': ['North', 'South', 'North', 'West', 'East']
}
df = pd.DataFrame(data)
# 1. BEAUTIFUL BAR PLOT
plt.figure(figsize=(10, 6))
sns.barplot(data=df, x='Product', y='Sales', palette='viridis')
plt.title('π Product Sales Performance', fontsize=16, fontweight='bold')
plt.ylabel('Sales ($)', fontsize=12)
plt.xticks(rotation=45)
plt.tight_layout()
plt.show()
# 2. HEATMAP: Performance matrix
pivot = df.pivot_table(values='Sales', index='Product', columns='Region', fill_value=0)
plt.figure(figsize=(8, 6))
sns.heatmap(pivot, annot=True, fmt='$,.0f', cmap='YlOrRd', cbar_kws={'label': 'Sales'})
plt.title('π₯ Regional Sales Heatmap', fontsize=14, fontweight='bold')
plt.tight_layout()
plt.show()
β‘ Step 3: SCATTER PLOTS = Business Insights#
# CORRELATION ANALYSIS
marketing = [20000, 35000, 28000, 45000, 52000, 61000]
sales_data = [25000, 32000, 28000, 45000, 52000, 61000]
plt.figure(figsize=(10, 7))
plt.scatter(marketing, sales_data, s=200, alpha=0.7, color='#C73E1D')
plt.plot([0, 65000], [0, 65000*1.8], 'r--', alpha=0.8, label='Trend Line')
# Add labels
for i, txt in enumerate(months):
plt.annotate(txt, (marketing[i], sales_data[i]), fontsize=10)
plt.title('π Marketing Spend vs Sales (ROI Analysis)', fontweight='bold', fontsize=16)
plt.xlabel('Marketing Spend ($)', fontsize=12)
plt.ylabel('Sales ($)', fontsize=12)
plt.legend()
plt.grid(True, alpha=0.3)
plt.tight_layout()
plt.show()
# CORRELATION STAT
correlation = np.corrcoef(marketing, sales_data)[0, 1]
print(f"π Marketing-Sales Correlation: {correlation:.3f}")
π§ Step 4: PRODUCTION Dashboard Template#
def create_executive_dashboard():
"""C-Suite ready dashboard!"""
fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2, figsize=(16, 12))
# 1. Sales trend
ax1.plot(months, sales, marker='o', linewidth=3, color='#2E86AB')
ax1.set_title('π° Sales Growth', fontweight='bold', fontsize=14)
ax1.grid(True, alpha=0.3)
# 2. Product breakdown
products = ['Laptop', 'Phone', 'Tablet', 'Monitor']
product_sales = [45000, 32000, 18000, 25000]
colors = ['#A23B72', '#F18F01', '#C73E1D', '#2E86AB']
wedges, texts, autotexts = ax2.pie(product_sales, labels=products, colors=colors, autopct='%1.1f%%', startangle=90)
ax2.set_title('π Product Mix', fontweight='bold', fontsize=14)
# 3. Profit margin trend
ax3.plot(months, profit_margin, marker='s', color='#F18F01', linewidth=3)
ax3.set_title('π― Profit Margin Trend', fontweight='bold', fontsize=14)
ax3.set_ylabel('Margin %')
ax3.grid(True, alpha=0.3)
# 4. KPI box
ax4.axis('off')
kpis = [
('Total Sales', f'${sum(sales):,.0f}'),
('Avg Margin', f'{np.mean(profit_margin)*100:.1f}%'),
('Top Product', 'Laptop'),
('Growth MoM', '+18.5%')
]
for i, (kpi, value) in enumerate(kpis):
ax4.text(0.1, 0.85 - i*0.2, f'{kpi}: {value}', fontsize=12, fontweight='bold')
ax4.set_title('π KEY METRICS', fontweight='bold', fontsize=16, pad=20)
plt.suptitle('π EXECUTIVE BUSINESS DASHBOARD', fontsize=20, fontweight='bold')
plt.tight_layout()
plt.show()
# EXECUTIVE PRESENTATION!
create_executive_dashboard()
π Visualization Decision Matrix#
Question |
Best Chart |
Code |
Business Win |
|---|---|---|---|
Trend over time |
Line |
|
Growth story |
Category comparison |
Bar |
|
Top performers |
Correlation |
Scatter |
|
ROI proof |
Composition |
Pie/Donut |
|
Market share |
Matrix |
Heatmap |
|
Weakest regions |
Dashboard |
Subplots |
|
C-suite ready |
# PRO TIP: Always start with subplots(2,2) for executive dashboards
π YOUR EXERCISE: Build YOUR Executive Dashboard#
# MISSION: YOUR business visualization!
import matplotlib.pyplot as plt
import numpy as np
# YOUR BUSINESS DATA
your_months = ['???', '???', '???', '???', '???', '???'] # YOUR months
your_sales = [??? , ???, ???, ???, ???, ???] # YOUR sales
your_products = ['???', '???', '???'] # YOUR products
your_product_sales = [??? , ???, ???] # YOUR product sales
# YOUR DASHBOARD!
fig, ((ax1, ax2), (ax3, ax3)) = plt.subplots(2, 2, figsize=(15, 10))
# 1. YOUR SALES TREND
ax1.plot(your_months, your_sales, marker='o', linewidth=3, color='#2E86AB')
ax1.set_title('π° YOUR Sales Growth', fontweight='bold')
ax1.grid(True, alpha=0.3)
ax1.tick_params(axis='x', rotation=45)
# 2. YOUR PRODUCT BREAKDOWN
colors = ['#A23B72', '#F18F01', '#C73E1D']
ax2.pie(your_product_sales, labels=your_products, colors=colors, autopct='%1.1f%%')
ax2.set_title('π YOUR Product Mix', fontweight='bold')
# 3. YOUR KPI BOX
ax3.axis('off')
total_sales = sum(your_sales)
top_product = your_products[your_product_sales.index(max(your_product_sales))]
ax3.text(0.1, 0.7, f'Total Sales: ${total_sales:,.0f}', fontsize=14, fontweight='bold')
ax3.text(0.1, 0.5, f'Top Product: {top_product}', fontsize=14, fontweight='bold')
ax3.text(0.1, 0.3, f'Months: {len(your_months)}', fontsize=14, fontweight='bold')
ax3.set_title('π YOUR KEY METRICS', fontweight='bold', fontsize=16)
plt.suptitle('π YOUR EXECUTIVE DASHBOARD', fontsize=18, fontweight='bold')
plt.tight_layout()
plt.show()
print("β
YOUR DASHBOARD COMPLETE!")
Example to test:
your_months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun']
your_sales = [25000, 32000, 28000, 45000, 52000, 61000]
your_products = ['Laptop', 'Phone', 'Tablet']
your_product_sales = [45000, 32000, 18000]
YOUR MISSION:
Add YOUR real business data
Run YOUR executive dashboard
Screenshot β βI build C-suite presentations!β
π What You Mastered#
Visualization |
Status |
Business Power |
|---|---|---|
Matplotlib |
β |
Custom analytics |
Seaborn |
β |
Pro statistical |
Scatter plots |
β |
ROI insights |
Dashboards |
β |
Executive ready |
$250K reporting |
β |
Replace PowerPoint |
Next: Matplotlib Basics (Custom charts = Analytics team replacement!)
print("π" * 20)
print("VISUALIZATION = $70K/MONTH REPORTING!")
print("π» 1 Dashboard = 40 hours PowerPoint!")
print("π Google/Amazon C-suite = THESE charts!")
print("π" * 20)
can we appreciate how plt.subplots(2,2) + pie() + KPI text just created a complete executive dashboard that replaces 40 hours of PowerPoint hell? Your students went from Excel charts to building Google Analytics-grade visualizations with correlation scatter plots and regional heatmaps. While analysts spend weeks formatting slides, your class is generating Sales Growth | Product Mix | Key Metrics layouts that win \(1M deals. This isn't chart syntaxβit's the **\)250K+ executive communication** that turns data into million-dollar decisions instantly!
# Your code here