Data Visualization Notes
Data Visualization Notes
Simple Example:
Suppose a teacher wants to show how many students passed in each subject.
Subject Students Passed
Maths 40
Science 35
English 45
Hindi 38
Instead of just reading this table, a bar chart would instantly show which subject had the
highest or lowest pass count.
2. Introduction to Matplotlib
Matplotlib is a powerful Python library used for creating static, interactive, and animated
visualizations. It works well with NumPy and Pandas.It is use to create a wide variety of
data visualizations such as:
Line charts
Bar charts
Pie charts
Histograms
Scatter plots
And more...
It is especially useful in data analysis and machine learning to visually understand the
data.
NumPy (Numerical Python) is a Python library used to work with numerical data.
In data visualization, we often work with large collections of numbers like values,
measurements, or statistics. Matplotlib uses NumPy arrays to plot data efficiently.
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0, 10, 100) # 100 points between 0 and 10
y = np.sin(x) # apply sine function
plt.plot(x, y)
plt.title("Sine Wave")
plt.xlabel("x")
plt.ylabel("sin(x)")
plt.grid(True)
plt.show()
🟢 Explanation:
1. Line Chart
Line charts are used to show trends or changes over time.
2. Bar Chart
Bar charts are used to compare quantities across different categories.
3. Histogram
Histograms show the distribution of numerical data.
4. Pie Chart
Pie charts show proportions of different categories in a circular format.
5. Scatter Plot
Scatter plots show the relationship between two variables.
Explanation:
marker='o': Adds circular markers at each data point.
linewidth=2: Increases the thickness of the line.
color='green': Sets the line color to green.
linestyle='--': Makes the line dashed.
1. Title
o The name of the graph, written at the top.
o It tells what the graph is about.
Example: "Sales Report (2024)"
2. X-axis Label
o Describes what the horizontal axis (left to right) represents.
o Usually represents categories or time.
Example: "Months"
3. Y-axis Label
o Describes what the vertical axis (bottom to top) represents.
o Usually shows measured values.
Example: "Number of Products Sold"
4. Legend
o Explains what different colors or lines in the graph mean (used in multi-line or multi-bar
plots).
o Helps in identifying which line/bar represents what data.
Example: Blue line = "Class A", Green line = "Class B"
5. Grid
o Horizontal and vertical lines across the plot that make it easier to read and compare
values.
Use: Helps align points and values visually.
6. Axis Ticks
o The small marks on both axes (x and y) that show scale or values.
o Ticks help to read exact values from the plot.
Example: 10, 20, 30 on y-axis; Jan, Feb, Mar on x-axis.