By IQRA MUSHTAQ
Intro to Matplotlib
Python library for plotting and visualization
Essential for understanding AI data and model outputs
Works closely with NumPy arrays and OpenCV images
What is OpenCV?
●
OpenCV stands for Computer Vision Library
It is used for image and video processing
Image reading and displaying
Face detection and object recognition
Image filtering and transformation
Used in AI and Machine Learning projects
Installation of Matplotlib
python -m pip install matplotlib
Install OpenCV
python -m pip install opencv-python
Draw a line in a diagram from position (0,0) to position (6,250)
import [Link] as plt
import numpy as np
xpoints = [Link]([0, 6])
ypoints = [Link]([0, 250])
[Link](xpoints, ypoints)
[Link]()
Matplotlib Labels and Title
import numpy as np
import [Link] as plt
x = [Link]([80, 85, 90, 95, 100, 105, 110, 115, 120, 125])
y = [Link]([240, 250, 260, 270, 280, 290, 300, 310, 320, 330])
[Link](x, y)
[Link]("Sports Watch Data")
[Link]("Average Pulse")
[Link]("Calorie Burnage")
[Link]()
Displaying Images
import cv2
import [Link] as plt
# Load grayscale image
img = [Link]("[Link]", 0) # 0 for grayscale
[Link](img, cmap='gray')
[Link]("Grayscale Image")
[Link]('off')
[Link]()
Image Conversion: Color, Grayscale & Binary
import cv2
import [Link] as plt
img = [Link]("[Link]")
gray = [Link](img, cv2.COLOR_BGR2GRAY)
binary = [Link](gray, 127, 255, cv2.THRESH_BINARY)
[Link](1,3,1)
[Link]([Link](img, cv2.COLOR_BGR2RGB))
[Link]("Color")
[Link]("off")
[Link](1,3,2)
[Link](gray, cmap="gray")
[Link]("Gray")
[Link]("off")
[Link](1,3,3)
[Link](binary, cmap="gray")
[Link]("Binary")
[Link]("off")
[Link]()
Histogram
A histogram is a graph showing frequency distributions.
It is a graph showing the number of observations within each given
interval.
Example: Say you ask for the height of 250 people, you might end
up with a histogram like this
DATA DISTRIBUTION
import [Link] as plt
import numpy as np
x = [Link](170, 10, 250)
[Link](x)
[Link]()
Model Accuracy Graph
import [Link] as plt
epochs = [1,2,3,4,5]
accuracy = [0.60, 0.70, 0.78, 0.85, 0.90]
[Link](epochs, accuracy)
[Link]("Model Accuracy")
[Link]("Epochs")
[Link]("Accuracy")
[Link]()
Loss Graph
import [Link] as plt
epochs = [1,2,3,4,5]
loss = [0.9, 0.7, 0.5, 0.3, 0.2]
[Link](epochs, loss)
[Link]("Model Loss")
[Link]("Epochs")
[Link]("Loss")
[Link]()