Để thay đổi độ dày của hatch (đường kẻ chéo) trong Matplotlib, ta đặt hatch.linewidth trong rcParams.
Các bước thực hiện
- Thiết lập kích thước hình và khoảng đệm.
- Tạo x, y=sin(x) bằng NumPy.
- Đặt plt.rcParams['hatch.linewidth'] = 1.
- Vẽ scatter với marker vuông, hatch="/", linewidth=0.05.
- 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 = np.linspace(-5, 5, 25)
y = np.sin(x)
plt.rcParams['hatch.linewidth'] = 1
plt.scatter(x, y, s=700, marker='s', linewidth=0.05, facecolor='red', hatch='/', alpha=.7)
plt.show()
Kết quả
