ในการวาดจุดเพิ่มเติมบน scatter plot ใน matplotlib สามารถทำตามขั้นตอนดังนี้:
ขั้นตอน
ตั้งค่าขนาดรูปและปรับ padding ระหว่างและรอบ subplots
สร้างรายการข้อมูล x และ y
สร้าง scatter plot ด้วย x และ y
วาดจุดเพิ่มเติมด้วย marker='*'
แสดงรูปด้วยเมธอด show()
ตัวอย่าง
from matplotlib import pyplot as plt # ตั้งค่าขนาดรูป plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True # รายการข้อมูล x = [1, 2, 6, 4] y = [1, 5, 2, 3] # Scatter plot plt.scatter(x, y, c=x, cmap='hot') plt.plot([3, 4], [6, 7], marker='*', ls='none', ms=20) # แสดง plot plt.show()
ผลลัพธ์
จะแสดง scatter plot 4 จุด สีตามค่า x พร้อมจุดเพิ่มเติม 2 จุด ดาวสีใหญ่
