Để vẽ phân phối song biến kết hợp, ta sử dụng phương thức scatter() với độ trong suốt (alpha) thấp để thấy mật độ điểm.
Các bước
- Thiết lập figure size và autolayout.
- Tạo dữ liệu x, y có tương quan bằng NumPy.
- Tạo figure và subplots.
- Vẽ scatter plot với alpha=0.08 và colormap.
- Hiển thị bằng 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
x = 2 * np.random.randn(5000)
y = x + np.random.randn(5000)
fig, ax = plt.subplots()
_ = ax.scatter(x, y, alpha=0.08, cmap="copper", c=x)
plt.show()
Kết quả
