Các bước
- Thiết lập kích thước hình và padding.
- Tạo figure và subplots.
- Khởi tạo biến
N cho số mẫu.
- Vẽ dữ liệu
x, y bằng plot().
- Đặt
xlabel ở vị trí right, ylabel ở top.
- Gọi
show().
Ví dụ
import numpy as np
from matplotlib import pyplot as plt
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
fig, ax = plt.subplots()
N = 10
x = np.random.rand(N)
y = np.random.rand(N)
ax.plot(x, y)
ax.set_xlabel("X-axis", loc="right")
ax.set_ylabel("Y-axis", loc="top")
plt.show()
Kết quả
