Week6-Matplotlib
Week6-Matplotlib
1. Introduction to Matplotlib
Matplotlib is a powerful Python library for creating static, animated, and interactive
visualizations. It is widely used in data analysis, machine learning, and scientific research.
Key Features:
Simple syntax similar to MATLAB
Customizable plots
import numpy as np
y = np.sin(x)
plt.xlabel('X Axis')
plt.ylabel('Y Axis')
plt.show()
y = np.random.rand(50)
plt.xlabel('X')
plt.ylabel('Y')
plt.title('Scatter Plot')
plt.show()
values = [3, 7, 1, 8]
plt.title('Bar Chart')
plt.show()
plt.show()
plt.plot(x, y)
plt.grid(True)
plt.show()
axs[0, 0].plot(x, y)
axs[0, 1].scatter(x, y)
plt.show()
Heatmaps
sns.heatmap(data, cmap='coolwarm')
plt.show()
plt.subplot(1, 2, 1)
plt.plot(x, y, 'g')
plt.subplot(1, 2, 2)
plt.scatter(x, y, color='b')
plt.show()
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
x = np.linspace(-5, 5, 100)
y = np.linspace(-5, 5, 100)
X, Y = np.meshgrid(x, y)
Z = np.sin(np.sqrt(X**2 + Y**2))
ax.plot_surface(X, Y, Z, cmap='viridis')
plt.show()
8. Case Studies
plt.title('Monthly Sales')
plt.xlabel('Month')
plt.ylabel('Sales ($)')
plt.show()
plt.title('Temperature Variation')
plt.xlabel('Days')
plt.ylabel('Temperature (°C)')
plt.show()
plt.legend()
plt.xlabel('Days')
plt.show()