Data Visualization Using Matplotlib
# Lecture Module: Data Visualization Using Matplotlib
## **1. Introduction to Data Visualization**
### **Importance of Data Visualization**
- Helps in understanding and interpreting data better.
- Facilitates decision-making with clear visual representation.
### **Example**: Simple Line Plot
import [Link] as plt
[Link]([1, 2, 3, 4], [1, 4, 9, 16])
[Link]("Simple Line Plot")
[Link]()
## **2. Setting Up Matplotlib**
### **Installation**
# pip install matplotlib
### **Basic Usage**
import [Link] as plt
[Link]()
[Link]([0, 1, 2], [0, 1, 4])
[Link]("X-axis")
[Link]("Y-axis")
[Link]("Basic Plot")
[Link]()
## **3. Creating Basic Plots**
### **Line Plot**
x = [0, 1, 2, 3]
y = [0, 1, 4, 9]
[Link](x, y, label="y = x^2", color="blue", linestyle="--",
linewidth=2)
[Link]("X-axis")
[Link]("Y-axis")
[Link]("Line Plot Example")
[Link]()
[Link]()
### **Scatter Plot**
x = [5, 7, 8, 7]
y = [99, 86, 87, 88]
[Link](x, y, color="red", label="Data Points", s=100)
[Link]("X-axis")
[Link]("Y-axis")
[Link]("Scatter Plot Example")
[Link]()
[Link]()
### **Bar Chart**
categories = ["A", "B", "C"]
values = [3, 7, 5]
[Link](categories, values, color="blue", width=0.4)
[Link]("Categories")
[Link]("Values")
[Link]("Bar Chart Example")
[Link]()
## **4. Customizing Plots**
### **Gridlines and Annotations**
[Link]([1, 2, 3], [1, 4, 9])
[Link](True, linestyle='--', linewidth=0.5)
[Link]("Peak", xy=(2, 4), xytext=(1.5, 7),
arrowprops=dict(facecolor='black', shrink=0.05))
[Link]()
### **Legends**
[Link]([1, 2, 3], [1, 4, 9], label="Quadratic")
[Link](loc="upper left", fontsize=10, title="Legend")
[Link]()
### **Subplots**
[Link](1, 2, 1)
[Link]([1, 2, 3], [1, 4, 9])
[Link]("Subplot 1")
[Link](1, 2, 2)
[Link]([1, 2, 3], [1, 2, 3])
[Link]("Subplot 2")
[Link]()
## **5. Advanced Visualizations**
### **Histogram**
data = [1, 1, 2, 2, 2, 3, 3, 4]
[Link](data, bins=4, color="purple", alpha=0.7, edgecolor="black")
[Link]("Histogram Example")
[Link]()
### **Box Plot**
data = [7, 8, 5, 6, 9, 4, 10, 12]
[Link](data, notch=True, patch_artist=True,
boxprops=dict(facecolor="lightblue"))
[Link]("Box Plot Example")
[Link]()
### **Pie Chart**
labels = ["A", "B", "C"]
sizes = [30, 45, 25]
explode = (0.1, 0, 0)
[Link](sizes, labels=labels, autopct="%1.1f%%", startangle=90,
explode=explode)
[Link]("Pie Chart Example")
[Link]()
### **Heatmap**
import numpy as np
data = [Link](6, 6)
[Link](data, cmap="hot", interpolation="nearest")
[Link]()
[Link]("Heatmap Example")
[Link]()
## **6. Case Study and Hands-On Session**
### **Example Dataset Analysis**
import pandas as pd
data = [Link]({"Month": ["Jan", "Feb", "Mar"], "Sales": [200,
250, 300]})
[Link](data["Month"], data["Sales"], color="orange")
[Link]("Sales Data Analysis")
[Link]()