ตั้งค่าความหนาของ hatch pattern ด้วย plt.rcParams['hatch.linewidth'] = ค่า ก่อนพลอต แล้วใช้ hatch='/' ใน plt.scatter() พร้อม marker='s' (สี่เหลี่ยม)
ขั้นตอนการทำงาน
- ตั้งค่าขนาดรูปและเลย์เอาต์
- สร้างข้อมูล x, y = sin(x)
- ตั้งค่า hatch linewidth:
plt.rcParams['hatch.linewidth'] = 1 - พลอต scatter marker สี่เหลี่ยม มี hatch='/', facecolor, alpha
- แสดงผล
ตัวอย่างโค้ด
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=0.7)
plt.show()
ผลลัพธ์
