Data Visualization Using Python

Learn how to convert Python data into meaningful charts and graphs using Matplotlib, Seaborn, and Pandas with practical real-time business examples.

What is Data Visualization?

Data visualization is the process of representing data using charts, graphs, and plots so that patterns, trends, comparisons, and relationships can be understood quickly.

Raw Data
→
Prepare Data
→
Create Chart
→
Find Insight
→
Make Decision

Matplotlib

A flexible Python library for creating line charts, bar charts, pie charts, scatter plots, and many other visualizations.

Seaborn

A statistical visualization library built on top of Matplotlib that makes many analytical charts easier.

Pandas

Provides convenient plotting capabilities directly from DataFrames and Series.

Business Insights

Visualizations help identify sales trends, product performance, customer behavior, and other patterns.

1. Installing Visualization Libraries

Install the main libraries used for Python data visualization.

Install Libraries
pip install matplotlib pandas seaborn

In many Python environments, Pandas and Matplotlib may already be installed.

2. Importing the Libraries
Python
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
Common aliases: pd is commonly used for Pandas, plt for Matplotlib, and sns for Seaborn.
3. Creating a Real-Time Sales Dataset

Suppose an online store wants to visualize its monthly sales.

Python
import pandas as pd

sales = pd.DataFrame({
    "Month": [
        "January", "February", "March",
        "April", "May", "June"
    ],
    "Sales": [
        120000, 145000, 132000,
        168000, 175000, 190000
    ]
})

print(sales)
Real-Time Scenario: The sales team wants to understand whether revenue is increasing month by month.
4. Basic Line Chart

A line chart is useful for showing trends over time.

Line Chart
plt.plot(
    sales["Month"],
    sales["Sales"],
    marker="o"
)

plt.title("Monthly Sales")
plt.xlabel("Month")
plt.ylabel("Sales")

plt.show()
Use Case: Line charts are commonly used for monthly revenue, website traffic, stock prices, and production trends.
5. Adding a Grid to a Chart
Python
plt.plot(
    sales["Month"],
    sales["Sales"],
    marker="o"
)

plt.title("Monthly Sales")
plt.xlabel("Month")
plt.ylabel("Sales")

plt.grid(True)

plt.show()

A grid can make values easier to compare visually.

6. Creating a Bar Chart

Bar charts are useful for comparing different categories.

Python
products = ["Laptop", "Phone", "Tablet", "Headphones"]
sales = [250000, 180000, 120000, 75000]

plt.bar(products, sales)

plt.title("Product Sales")
plt.xlabel("Product")
plt.ylabel("Sales")

plt.show()
7. Horizontal Bar Chart

Horizontal bars can be easier to read when category names are long.

Python
products = [
    "Laptop",
    "Smartphone",
    "Tablet",
    "Wireless Headphones"
]

sales = [250000, 180000, 120000, 75000]

plt.barh(products, sales)

plt.title("Product Sales")
plt.xlabel("Sales")
plt.ylabel("Product")

plt.show()
8. Adding Values to a Bar Chart
Python
products = ["Laptop", "Phone", "Tablet"]
sales = [250000, 180000, 120000]

bars = plt.bar(products, sales)

for bar in bars:
    plt.text(
        bar.get_x() + bar.get_width() / 2,
        bar.get_height(),
        str(bar.get_height()),
        ha="center",
        va="bottom"
    )

plt.title("Product Sales")
plt.ylabel("Sales")

plt.show()
Adding labels makes the exact values easier to identify without estimating from the axis.
9. Creating a Pie Chart

Pie charts show how categories contribute to a whole.

Python
products = [
    "Laptop",
    "Phone",
    "Tablet",
    "Headphones"
]

sales = [250000, 180000, 120000, 75000]

plt.pie(
    sales,
    labels=products,
    autopct="%1.1f%%"
)

plt.title("Sales Distribution")

plt.show()
10. Creating a Scatter Plot

Scatter plots are useful for understanding relationships between two numerical variables.

Python
advertising = [10, 20, 30, 40, 50, 60]
sales = [100, 150, 180, 230, 280, 320]

plt.scatter(advertising, sales)

plt.title("Advertising vs Sales")
plt.xlabel("Advertising Spend")
plt.ylabel("Sales")

plt.show()
Business Question: Does increasing advertising spending appear to be associated with higher sales?
11. Creating a Histogram

Histograms show how numerical values are distributed.

Python
order_values = [
    1200, 1500, 1800, 2200, 2500,
    2700, 3100, 3200, 3500, 3900,
    4200, 4500, 4800, 5000
]

plt.hist(order_values, bins=5)

plt.title("Order Value Distribution")
plt.xlabel("Order Value")
plt.ylabel("Number of Orders")

plt.show()
12. Customizing Chart Size
Python
plt.figure(figsize=(10, 5))

plt.plot(
    sales["Month"],
    sales["Sales"],
    marker="o"
)

plt.title("Monthly Sales")
plt.xlabel("Month")
plt.ylabel("Sales")

plt.show()

figsize controls the width and height of the visualization.

13. Customizing Line Style
Python
plt.plot(
    sales["Month"],
    sales["Sales"],
    marker="o",
    linestyle="--",
    linewidth=2
)

plt.title("Monthly Sales")

plt.show()
Common line styles include solid, dashed, dotted, and dash-dot.
14. Adding a Legend
Python
plt.plot(
    sales["Month"],
    sales["Sales"],
    marker="o",
    label="Sales"
)

plt.title("Monthly Sales")
plt.xlabel("Month")
plt.ylabel("Sales")

plt.legend()

plt.show()
15. Comparing Two Lines

Multiple lines are useful when comparing two related trends.

Python
months = [
    "Jan", "Feb", "Mar",
    "Apr", "May", "Jun"
]

online_sales = [
    100000, 120000, 135000,
    150000, 175000, 195000
]

store_sales = [
    140000, 145000, 150000,
    155000, 160000, 165000
]

plt.plot(
    months,
    online_sales,
    marker="o",
    label="Online"
)

plt.plot(
    months,
    store_sales,
    marker="o",
    label="Store"
)

plt.title("Online vs Store Sales")
plt.xlabel("Month")
plt.ylabel("Sales")

plt.legend()
plt.show()
16. Using Pandas Plotting

Pandas can create charts directly from DataFrames.

Python
sales.plot(
    x="Month",
    y="Sales",
    kind="line",
    marker="o"
)

plt.title("Monthly Sales")
plt.show()
17. Real-Time Example: Monthly Revenue

A finance team wants to understand the company's monthly revenue trend.

Python
import pandas as pd
import matplotlib.pyplot as plt

revenue = pd.DataFrame({
    "Month": [
        "Jan", "Feb", "Mar",
        "Apr", "May", "Jun"
    ],
    "Revenue": [
        450000, 480000, 510000,
        495000, 550000, 590000
    ]
})

plt.figure(figsize=(10, 5))

plt.plot(
    revenue["Month"],
    revenue["Revenue"],
    marker="o"
)

plt.title("Monthly Revenue")
plt.xlabel("Month")
plt.ylabel("Revenue")

plt.grid(True)
plt.show()
Business Insight: The chart makes month-to-month revenue movement easier to identify.
18. Real-Time Example: Product Sales

An e-commerce manager wants to compare product performance.

Python
products = pd.DataFrame({
    "Product": [
        "Laptop",
        "Phone",
        "Tablet",
        "Monitor",
        "Headphones"
    ],
    "Sales": [
        450000,
        380000,
        210000,
        175000,
        95000
    ]
})

plt.figure(figsize=(10, 5))

plt.bar(
    products["Product"],
    products["Sales"]
)

plt.title("Product Sales")
plt.xlabel("Product")
plt.ylabel("Sales")

plt.xticks(rotation=20)

plt.show()
19. Real-Time Example: Sales by City
Python
city_sales = pd.DataFrame({
    "City": [
        "Pune",
        "Mumbai",
        "Delhi",
        "Bangalore",
        "Chennai"
    ],
    "Sales": [
        320000,
        450000,
        390000,
        520000,
        280000
    ]
})

plt.figure(figsize=(9, 5))

plt.barh(
    city_sales["City"],
    city_sales["Sales"]
)

plt.title("Sales by City")
plt.xlabel("Sales")
plt.ylabel("City")

plt.show()
Business Use: Regional managers can use this visualization to compare sales performance across locations.
20. Real-Time Example: Customer Age Distribution
Python
customers = pd.DataFrame({
    "Age": [
        21, 24, 25, 27, 29,
        31, 32, 34, 36, 38,
        41, 43, 45, 47, 52
    ]
})

plt.hist(
    customers["Age"],
    bins=5
)

plt.title("Customer Age Distribution")
plt.xlabel("Age")
plt.ylabel("Number of Customers")

plt.show()
Business Use: Marketing teams can understand the age distribution of their customer base.
21. Real-Time Example: Advertising vs Sales

A marketing team wants to investigate whether advertising expenditure is associated with sales.

Python
marketing = pd.DataFrame({
    "Advertising": [
        10000, 15000, 20000,
        25000, 30000, 35000,
        40000
    ],
    "Sales": [
        85000, 110000, 135000,
        160000, 185000, 220000,
        250000
    ]
})

plt.scatter(
    marketing["Advertising"],
    marketing["Sales"]
)

plt.title("Advertising vs Sales")
plt.xlabel("Advertising Spend")
plt.ylabel("Sales")

plt.show()
A scatter plot can reveal whether two numerical variables appear to move together, but visual association alone does not prove causation.
22. Real-Time Example: Department Salary Analysis
Python
employees = pd.DataFrame({
    "Department": [
        "IT",
        "HR",
        "Finance",
        "Sales",
        "Marketing"
    ],
    "AverageSalary": [
        85000,
        60000,
        75000,
        70000,
        68000
    ]
})

plt.bar(
    employees["Department"],
    employees["AverageSalary"]
)

plt.title("Average Salary by Department")
plt.xlabel("Department")
plt.ylabel("Average Salary")

plt.show()
23. Real-Time Example: Inventory Levels

A warehouse wants to visualize current stock levels.

Python
inventory = pd.DataFrame({
    "Product": [
        "Laptop",
        "Phone",
        "Tablet",
        "Monitor",
        "Mouse"
    ],
    "Stock": [
        25,
        8,
        40,
        6,
        75
    ]
})

plt.bar(
    inventory["Product"],
    inventory["Stock"]
)

plt.axhline(
    y=10,
    linestyle="--",
    label="Reorder Level"
)

plt.title("Inventory Levels")
plt.xlabel("Product")
plt.ylabel("Stock")

plt.legend()
plt.show()
Business Insight: Products below the reorder level may require replenishment.
24. Creating a Seaborn Bar Plot
Seaborn
import seaborn as sns
import matplotlib.pyplot as plt

sns.barplot(
    data=products,
    x="Product",
    y="Sales"
)

plt.title("Product Sales")
plt.xticks(rotation=20)

plt.show()

Seaborn provides convenient statistical visualization functions and works naturally with Pandas DataFrames.

25. Creating a Seaborn Box Plot

Box plots are useful for understanding distributions, medians, quartiles, and potential outliers.

Seaborn
import seaborn as sns
import matplotlib.pyplot as plt

sns.boxplot(
    data=customers,
    y="Age"
)

plt.title("Customer Age Distribution")

plt.show()
26. Creating a Seaborn Histogram
Seaborn
sns.histplot(
    data=customers,
    x="Age",
    bins=5
)

plt.title("Customer Age Distribution")

plt.show()
27. Creating a Seaborn Scatter Plot
Seaborn
sns.scatterplot(
    data=marketing,
    x="Advertising",
    y="Sales"
)

plt.title("Advertising vs Sales")

plt.show()
28. Adding a Regression Line

Seaborn can display a fitted regression line to help visually examine a relationship between numerical variables.

Seaborn
sns.regplot(
    data=marketing,
    x="Advertising",
    y="Sales"
)

plt.title("Advertising vs Sales")

plt.show()
Remember: A regression line is a statistical summary of the observed relationship. It does not by itself establish that one variable causes the other.
29. Creating a Heatmap

Heatmaps are useful for displaying relationships or values across a matrix.

Python
import seaborn as sns
import matplotlib.pyplot as plt

data = pd.DataFrame({
    "Product": ["Laptop", "Phone", "Tablet"],
    "Pune": [120, 150, 90],
    "Mumbai": [180, 200, 120],
    "Delhi": [150, 170, 100]
})

heatmap_data = data.set_index("Product")

sns.heatmap(
    heatmap_data,
    annot=True,
    fmt="d"
)

plt.title("Product Sales by City")

plt.show()
30. Correlation Heatmap

A correlation heatmap can help summarize relationships between numerical columns.

Python
numeric_data = pd.DataFrame({
    "Advertising": [10, 20, 30, 40, 50],
    "WebsiteVisitors": [100, 180, 250, 330, 420],
    "Sales": [80, 140, 200, 270, 350]
})

correlation = numeric_data.corr()

sns.heatmap(
    correlation,
    annot=True
)

plt.title("Correlation Matrix")

plt.show()
31. Multiple Charts in One Figure

Subplots allow multiple related visualizations to be presented together.

Python
fig, axes = plt.subplots(
    1,
    2,
    figsize=(12, 5)
)

axes[0].plot(
    sales["Month"],
    sales["Sales"],
    marker="o"
)

axes[0].set_title("Monthly Sales")

axes[1].bar(
    products["Product"],
    products["Sales"]
)

axes[1].set_title("Product Sales")

plt.tight_layout()
plt.show()
32. Saving a Chart as an Image

Charts can be saved for reports, presentations, dashboards, or business documents.

Python
plt.plot(
    sales["Month"],
    sales["Sales"],
    marker="o"
)

plt.title("Monthly Sales")

plt.savefig(
    "monthly_sales.png",
    dpi=300,
    bbox_inches="tight"
)

plt.show()
33. Formatting Currency Values

For financial reports, axis labels can be formatted so that values are easier to understand.

Python
import matplotlib.pyplot as plt
from matplotlib.ticker import FuncFormatter

sales = [120000, 145000, 132000, 168000, 190000]
months = ["Jan", "Feb", "Mar", "Apr", "May"]

plt.plot(
    months,
    sales,
    marker="o"
)

plt.gca().yaxis.set_major_formatter(
    FuncFormatter(lambda x, pos: f"₹{x:,.0f}")
)

plt.title("Monthly Sales")
plt.xlabel("Month")
plt.ylabel("Sales")

plt.show()
34. Real-Time Example: E-Commerce Dashboard Charts

An e-commerce company wants to create several visual summaries from its order data.

Python
import pandas as pd
import matplotlib.pyplot as plt

orders = pd.DataFrame({
    "Month": [
        "Jan", "Feb", "Mar",
        "Apr", "May", "Jun"
    ],
    "Orders": [
        120, 150, 175,
        160, 210, 240
    ],
    "Revenue": [
        240000, 300000, 350000,
        320000, 420000, 480000
    ]
})

fig, axes = plt.subplots(
    1,
    2,
    figsize=(12, 5)
)

axes[0].plot(
    orders["Month"],
    orders["Revenue"],
    marker="o"
)

axes[0].set_title("Monthly Revenue")
axes[0].set_xlabel("Month")
axes[0].set_ylabel("Revenue")

axes[1].bar(
    orders["Month"],
    orders["Orders"]
)

axes[1].set_title("Monthly Orders")
axes[1].set_xlabel("Month")
axes[1].set_ylabel("Orders")

plt.tight_layout()
plt.show()
Dashboard Insight: One visualization shows revenue trends while the other shows order volume.
35. Real-Time Example: Employee Performance
Python
employees = pd.DataFrame({
    "Employee": [
        "Amit",
        "Priya",
        "Rahul",
        "Sneha",
        "Vikas"
    ],
    "Sales": [
        120000,
        150000,
        98000,
        175000,
        135000
    ]
})

plt.figure(figsize=(9, 5))

plt.bar(
    employees["Employee"],
    employees["Sales"]
)

plt.title("Employee Sales Performance")
plt.xlabel("Employee")
plt.ylabel("Sales")

plt.show()
This type of chart can support operational reporting when the underlying metric and comparison period are clearly defined.
36. Real-Time Example: Website Traffic

A website owner wants to visualize daily visitors.

Python
days = [
    "Mon", "Tue", "Wed",
    "Thu", "Fri", "Sat", "Sun"
]

visitors = [
    1200, 1350, 1500,
    1480, 1800, 2400, 2200
]

plt.plot(
    days,
    visitors,
    marker="o"
)

plt.title("Weekly Website Traffic")
plt.xlabel("Day")
plt.ylabel("Visitors")

plt.grid(True)
plt.show()
37. Real-Time Example: Monthly Profit
Python
months = [
    "Jan", "Feb", "Mar",
    "Apr", "May", "Jun"
]

profit = [
    50000, 62000, 58000,
    75000, 82000, 95000
]

plt.bar(
    months,
    profit
)

plt.title("Monthly Profit")
plt.xlabel("Month")
plt.ylabel("Profit")

plt.show()
38. Choosing the Right Chart
📈

Line Chart

Best for trends over time, such as monthly sales or daily website traffic.

📊

Bar Chart

Best for comparing categories such as product sales or department performance.

🥧

Pie Chart

Best for showing parts of a meaningful whole when there are only a few categories.

🔵

Scatter Plot

Best for investigating relationships between two numerical variables.

📉

Histogram

Best for understanding the distribution of numerical data.

🔥

Heatmap

Useful for matrices, correlation analysis, and comparing values across two dimensions.

Business Question Recommended Chart
How are sales changing over time? Line Chart
Which product sells the most? Bar Chart
What percentage does each category contribute? Pie Chart
Are advertising and sales related? Scatter Plot
How are customer ages distributed? Histogram
How do numerical variables relate to each other? Heatmap
39. Real-Time Example: Sales by Category and Month

A company wants to compare multiple product categories across several months.

Python
months = [
    "Jan", "Feb", "Mar",
    "Apr", "May"
]

electronics = [
    120000, 140000, 155000,
    170000, 190000
]

clothing = [
    90000, 100000, 110000,
    125000, 135000
]

home = [
    70000, 85000, 80000,
    95000, 105000
]

plt.plot(
    months,
    electronics,
    marker="o",
    label="Electronics"
)

plt.plot(
    months,
    clothing,
    marker="o",
    label="Clothing"
)

plt.plot(
    months,
    home,
    marker="o",
    label="Home"
)

plt.title("Category Sales Trend")
plt.xlabel("Month")
plt.ylabel("Sales")

plt.legend()
plt.grid(True)

plt.show()
40. Creating a Dashboard-Style Visualization
₹59L
Illustrative Revenue
1,250
Illustrative Orders
₹4.7K
Illustrative AOV
24%
Illustrative Growth

In a real dashboard, these metrics would be calculated directly from the underlying business dataset rather than manually entered.

Python
fig, axes = plt.subplots(
    2,
    2,
    figsize=(12, 8)
)

# Revenue trend
axes[0, 0].plot(
    revenue["Month"],
    revenue["Revenue"],
    marker="o"
)

axes[0, 0].set_title("Revenue Trend")

# Product comparison
axes[0, 1].bar(
    products["Product"],
    products["Sales"]
)

axes[0, 1].set_title("Product Sales")
axes[0, 1].tick_params(axis="x", rotation=20)

# Customer age distribution
axes[1, 0].hist(
    customers["Age"],
    bins=5
)

axes[1, 0].set_title("Customer Age")

# Advertising relationship
axes[1, 1].scatter(
    marketing["Advertising"],
    marketing["Sales"]
)

axes[1, 1].set_title("Advertising vs Sales")

plt.tight_layout()
plt.show()
41. Real-Time Example: Complete Sales Visualization

The following example demonstrates a complete workflow using a real-world style sales dataset.

Complete Example
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns

sales = pd.DataFrame({
    "Product": [
        "Laptop", "Phone", "Laptop",
        "Tablet", "Phone", "Monitor",
        "Tablet", "Phone"
    ],
    "City": [
        "Pune", "Mumbai", "Delhi",
        "Pune", "Mumbai", "Delhi",
        "Pune", "Delhi"
    ],
    "Quantity": [
        2, 4, 1, 5,
        3, 2, 4, 5
    ],
    "Price": [
        60000, 30000, 60000, 25000,
        30000, 20000, 25000, 30000
    ]
})

# Calculate sales
sales["Revenue"] = (
    sales["Quantity"] *
    sales["Price"]
)

# Product summary
product_summary = sales.groupby(
    "Product"
)["Revenue"].sum().reset_index()

# City summary
city_summary = sales.groupby(
    "City"
)["Revenue"].sum().reset_index()

# Create dashboard
fig, axes = plt.subplots(
    1,
    2,
    figsize=(13, 5)
)

# Product chart
sns.barplot(
    data=product_summary,
    x="Product",
    y="Revenue",
    ax=axes[0]
)

axes[0].set_title("Revenue by Product")
axes[0].tick_params(axis="x", rotation=20)

# City chart
sns.barplot(
    data=city_summary,
    x="City",
    y="Revenue",
    ax=axes[1]
)

axes[1].set_title("Revenue by City")

plt.tight_layout()
plt.show()
Result: The visualization provides two complementary views: revenue by product and revenue by city.
42. Adding Annotations to Charts

Annotations can highlight important values or events.

Python
months = ["Jan", "Feb", "Mar", "Apr", "May"]
sales = [120000, 145000, 132000, 168000, 190000]

plt.plot(
    months,
    sales,
    marker="o"
)

max_sales = max(sales)
max_month = months[sales.index(max_sales)]

plt.annotate(
    "Highest Sales",
    xy=(max_month, max_sales),
    xytext=(max_month, max_sales + 15000),
    arrowprops=dict(arrowstyle="->")
)

plt.title("Monthly Sales")
plt.xlabel("Month")
plt.ylabel("Sales")

plt.show()
43. Data Visualization Workflow
Collect Data
→
Clean Data
→
Select Chart
→
Visualize
→
Interpret
  1. Collect the relevant data.
  2. Clean and validate the data.
  3. Understand the variables and their data types.
  4. Identify the business question.
  5. Select an appropriate visualization.
  6. Create the chart.
  7. Add meaningful titles and labels.
  8. Check the visualization for misleading presentation.
  9. Interpret the result in context.
  10. Use the insight to support reporting or decisions.
44. Common Data Visualization Mistakes
1. Choosing the Wrong Chart: A chart should match the question being answered.
2. Missing Labels: Always provide meaningful titles and axis labels.
3. Too Many Categories: Crowded charts can become difficult to interpret.
4. Misleading Scales: Axis ranges should be chosen carefully so that visual differences are not exaggerated or hidden.
5. Unnecessary Decoration: Visual elements should improve understanding rather than distract from the data.
45. Data Visualization Best Practices
  • Start with a clear business or analytical question.
  • Use the simplest chart that communicates the result clearly.
  • Choose line charts for ordered trends and time series.
  • Use bar charts for category comparisons.
  • Use scatter plots for relationships between numerical variables.
  • Use histograms for distributions.
  • Use pie charts only when part-to-whole comparison is meaningful.
  • Use meaningful titles and axis labels.
  • Keep charts readable and avoid unnecessary clutter.
  • Always interpret charts using the context of the underlying data.
  • Check for missing values and outliers before visualization.
  • Do not imply causation from a visual association alone.
  • Save important visualizations at an appropriate resolution.
46. Important Visualization Libraries
Library Main Use Common Functions
Matplotlib General-purpose plotting plot(), bar(), scatter()
Seaborn Statistical visualization barplot(), boxplot(), heatmap()
Pandas Quick DataFrame visualization df.plot()
47. Complete Real-Time E-Commerce Visualization Project

This final example combines Pandas, Matplotlib, and Seaborn to create a small business visualization workflow.

Complete Project
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns

# -----------------------------
# 1. Create sales data
# -----------------------------

sales = pd.DataFrame({
    "Month": [
        "Jan", "Feb", "Mar",
        "Apr", "May", "Jun"
    ],
    "Orders": [
        120, 150, 175,
        190, 220, 250
    ],
    "Revenue": [
        240000, 300000, 350000,
        390000, 450000, 520000
    ]
})

# -----------------------------
# 2. Create product data
# -----------------------------

products = pd.DataFrame({
    "Product": [
        "Laptop",
        "Phone",
        "Tablet",
        "Monitor",
        "Headphones"
    ],
    "Revenue": [
        450000,
        380000,
        220000,
        170000,
        90000
    ]
})

# -----------------------------
# 3. Create city data
# -----------------------------

cities = pd.DataFrame({
    "City": [
        "Pune",
        "Mumbai",
        "Delhi",
        "Bangalore",
        "Chennai"
    ],
    "Revenue": [
        320000,
        450000,
        390000,
        520000,
        280000
    ]
})

# -----------------------------
# 4. Create dashboard
# -----------------------------

fig, axes = plt.subplots(
    2,
    2,
    figsize=(14, 9)
)

# Monthly revenue
axes[0, 0].plot(
    sales["Month"],
    sales["Revenue"],
    marker="o"
)

axes[0, 0].set_title(
    "Monthly Revenue"
)

axes[0, 0].set_xlabel("Month")
axes[0, 0].set_ylabel("Revenue")
axes[0, 0].grid(True)

# Monthly orders
axes[0, 1].bar(
    sales["Month"],
    sales["Orders"]
)

axes[0, 1].set_title(
    "Monthly Orders"
)

axes[0, 1].set_xlabel("Month")
axes[0, 1].set_ylabel("Orders")

# Product revenue
sns.barplot(
    data=products,
    x="Product",
    y="Revenue",
    ax=axes[1, 0]
)

axes[1, 0].set_title(
    "Revenue by Product"
)

axes[1, 0].tick_params(
    axis="x",
    rotation=20
)

# City revenue
sns.barplot(
    data=cities,
    x="City",
    y="Revenue",
    ax=axes[1, 1]
)

axes[1, 1].set_title(
    "Revenue by City"
)

axes[1, 1].tick_params(
    axis="x",
    rotation=20
)

plt.tight_layout()

plt.savefig(
    "ecommerce_dashboard.png",
    dpi=300,
    bbox_inches="tight"
)

plt.show()
Project Result: The final dashboard contains monthly revenue, monthly orders, product revenue, and city revenue visualizations. This pattern can be extended to real CSV or database data.
48. Important Data Visualization Rules
  1. Understand the data before creating charts.
  2. Define the question that the visualization should answer.
  3. Choose the chart type according to the data and question.
  4. Use line charts for trends and ordered data.
  5. Use bar charts for category comparisons.
  6. Use scatter plots for numerical relationships.
  7. Use histograms for distributions.
  8. Use heatmaps for matrices and correlation summaries.
  9. Use clear titles and axis labels.
  10. Keep visualizations simple and readable.
  11. Do not distort comparisons with inappropriate scales.
  12. Always inspect the underlying data before interpreting a chart.
  13. Remember that correlation or visual association does not automatically imply causation.
  14. Use visualizations to communicate evidence and patterns clearly.
Key Idea: Good data visualization is not just about making attractive charts. It is about presenting the right information in a form that makes the underlying pattern easier to understand.

Python Data Visualization • Real-Time Examples • Data Analysis Learning