Import thư viện Matpolib
import matplotlib.pyplot as plt
Thao tác trên data Frame nên import thêm Pandas
import pandas as pd
Tạo 1 data mẫu từ dictionary
data = {'x': [1,2,3,4,5,6],'y': [10,11,12,13,14,15]}
Chuyển data sang data Frame
df = pd.DataFrame(data)
Lấy giá trị x, y từ data Frame
x = df['x']y = df['y']
Sử dụng matpolib để vẽ, đặt tên cho trục x, y và tên biểu đồ
plt.plot(x,y,'r')plt.xlabel('X axis')plt.ylabel('Y axis')plt.title('Draw line in matpolitb')plt.show()
Kết quả
Thay đổi data ban đầu xem thế nào ?
data = {'x': [0.1,2.2,3.5,4.2,5.5,6.9],'y': [10,11,12,13,14,15]}