Các bước
- Thiết lập kích thước hình và padding.
- Khởi tạo biến
ncho số điểm. - Vẽ scatter plot bằng
scatter(). - Vẽ đường bằng
plot(). - Giới hạn trục X bằng
xlim(). - 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 n = 100 x = np.random.rand(n) y = np.random.rand(n) plt.scatter(x, y, c=x) plt.plot([0.1, 0.4, 0.3, 0.2]) plt.xlim(0, 1) plt.show()
Kết quả
