Week8 PBD
Week8 PBD
1. Introduction to Matplotlib
Matplotlib is a comprehensive library for creating static, animated, and interactive visualizations in
Python.
Features:
2D plotting library.
Installation:
Importing:
x = [1, 2, 3, 4, 5]
plt.plot(x, y)
plt.title("Basic Plot")
plt.xlabel("X-axis")
plt.ylabel("Y-axis")
plt.grid(True)
plt.show()
Components of a Plot:
3. Line Plots
Example:
x = [1, 2, 3, 4, 5]
y = [2, 3, 5, 7, 11]
plt.show()
Customizations:
4. Area Plots
Example:
days = [1, 2, 3, 4, 5]
plt.title("Area Plot")
plt.show()
Tip:
5. Histograms
Example:
import numpy as np
data = np.random.randn(1000)
plt.title("Histogram")
plt.xlabel("Value")
plt.ylabel("Frequency")
plt.show()
Parameters:
6. Bar Charts
Example:
plt.title("Bar Chart")
plt.xlabel("Categories")
plt.ylabel("Values")
plt.show()
plt.show()
7. Pie Charts
Example:
plt.title("Pie Chart")
plt.show()
Parameters:
8. Box Plots
Example:
data = [7, 15, 13, 18, 21, 30, 45, 40, 50, 60]
plt.boxplot(data)
plt.title("Box Plot")
plt.show()
Interpretation:
Dots: Outliers
9. Scatter Plots
Example:
x = [1, 2, 3, 4, 5]
y = [5, 4, 3, 2, 1]
plt.scatter(x, y, color='red')
plt.title("Scatter Plot")
plt.xlabel("X-axis")
plt.ylabel("Y-axis")
plt.show()
Useful For:
Correlation analysis.
Table: