Matplotlib is a powerful Python library for creating static, animated, and interactive visualizations. It's widely used in data science and scientific computing for plotting graphs and charts.
Installation 📦
To get started, install Matplotlib using pip:
pip install matplotlib
Basic Plot Types 📈
Here are common plot types with examples:
Line Plot
import matplotlib.pyplot as plt plt.plot([1, 2, 3], [5, 7, 4]) plt.show()
Bar Chart
plt.bar(['A', 'B', 'C'], [10, 20, 15]) plt.show()
Scatter Plot
plt.scatter([1, 2, 3], [5, 7, 4], c='red') plt.show()
Customizing Plots 🎨
You can customize colors, labels, and styles:
plt.plot([1, 2, 3], [5, 7, 4], color='blue', linestyle='--', marker='o')
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.title('Customized Plot')
plt.grid(True)
plt.show()
Further Reading 📚
For advanced topics, check out our Matplotlib Advanced Tutorial.