Nội dung

CÁC BIỂU ĐỒ CƠ BẢN

1. Line Chart (Biểu đồ đường)

Dùng để thể hiện xu hướng theo thời gian.

import matplotlib.pyplot as plt

months = ["Jan","Feb","Mar","Apr"]
revenue = [1000,1500,1800,2000]

plt.plot(months,revenue)

plt.title("Revenue by Month")
plt.xlabel("Month")
plt.ylabel("Revenue")

plt.show()

2. Bar Chart (Biểu đồ cột)

Dùng để so sánh giữa các nhóm dữ liệu.

products = ["A","B","C"]
sales = [300,500,200]

plt.bar(products,sales)

plt.title("Sales by Product")

plt.show()

3. Pie Chart (Biểu đồ tròn)

Dùng để thể hiện tỷ lệ phần trăm.

regions = ["North","South","East","West"]
sales = [40,25,20,15]

plt.pie(sales,labels=regions,autopct="%1.1f%%")

plt.title("Sales by Region")

plt.show()

4. Histogram

Dùng để xem phân bố dữ liệu.

import numpy as np

data = np.random.normal(50,10,100)

plt.hist(data,bins=10)

plt.show()ư