Matplotlib Guide 📊📈

Data Visualization in Python

1. What is Matplotlib?

Matplotlib is a Python library used to create graphs, charts, and visualizations from data.

2. Installation

pip install matplotlib

3. Import

import matplotlib.pyplot as plt

4. Line Chart

x = [1,2,3]
y = [2,4,6]

plt.plot(x, y)
plt.show()

5. Bar Chart

plt.bar(["A","B","C"], [10,20,15])
plt.show()

6. Pie Chart

plt.pie([30,40,30], labels=["A","B","C"])
plt.show()

7. Scatter Plot

plt.scatter([1,2,3], [4,5,6])
plt.show()

8. Labels & Title

plt.title("My Chart")
plt.xlabel("X-axis")
plt.ylabel("Y-axis")

9. Save Chart

plt.savefig("chart.png")

10. Real Use Cases