Để vẽ dữ liệu CSV bằng Matplotlib và Pandas trong Python, chúng ta có thể thực hiện các bước sau:
- Thiết lập kích thước figure và điều chỉnh padding giữa và xung quanh subplots.
- Tạo danh sách header của file .CSV.
- Đọc file CSV với headers.
- Thiết lập index và vẽ dataframe.
- Để hiển thị figure, dùng phương thức show().
Ví dụ
import pandas as pd
import matplotlib.pyplot as plt
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
headers = ['Name', 'Age', 'Marks']
df = pd.read_csv('student.csv', names=headers)
df.set_index('Name').plot()
plt.show()
Kết quả

