> For the complete documentation index, see [llms.txt](https://www.nhasachso.io.vn/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.nhasachso.io.vn/truc-tuyen/interactive-blocks-1/tac-gia/nguyen-hong-phuong/sach-cong-cu-ai-python/phan-1-xu-ly-du-lieu/matplotlib-and-seaborn-ve-bieu-do-truc-quan-hoa-du-lieu.md).

# Matplotlib & Seaborn: Vẽ biểu đồ, trực quan hóa dữ liệu

#### **Matplotlib & Seaborn**

**Mục tiêu:** Trực quan hóa dữ liệu bằng biểu đồ để phân tích và truyền tải thông tin hiệu quả.

**📊 Matplotlib**

* Thư viện vẽ biểu đồ nền tảng mạnh mẽ và linh hoạt.
* Hỗ trợ đa dạng loại biểu đồ: đường (line), cột (bar), phân tán (scatter), histogram,...
* Tùy biến cao: màu sắc, nhãn, tiêu đề, kích thước, trục,...

**📈 Seaborn**

* Xây dựng dựa trên Matplotlib, thân thiện và đẹp mắt hơn.
* Hỗ trợ trực quan hóa thống kê nâng cao: heatmap, boxplot, violinplot,...
* Tích hợp tốt với **Pandas DataFrame**, giúp vẽ nhanh từ dữ liệu bảng.

**Ví dụ cơ bản:**

```python
import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd

# Tạo DataFrame mẫu
df = pd.DataFrame({
    'age': [22, 25, 30, 35, 40],
    'salary': [3000, 3500, 4000, 5000, 6000]
})

# Vẽ biểu đồ đường bằng Matplotlib
plt.plot(df['age'], df['salary'])
plt.xlabel('Tuổi')
plt.ylabel('Lương')
plt.title('Mối quan hệ Tuổi - Lương')
plt.show()

# Vẽ biểu đồ phân tán bằng Seaborn
sns.scatterplot(x='age', y='salary', data=df)
plt.show()
```

***
