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

plt.plot()

Growth story

Category comparison

Bar

sns.barplot()

Top performers

Correlation

Scatter

plt.scatter()

ROI proof

Composition

Pie/Donut

plt.pie()

Market share

Matrix

Heatmap

sns.heatmap()

Weakest regions

Dashboard

Subplots

plt.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:

  1. Add YOUR real business data

  2. Run YOUR executive dashboard

  3. 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