ในการพล็อตจุดกระจายด้วยสัญลักษณ์โคลเวอร์ใน Matplotlib เราสามารถทำตามขั้นตอนต่อไปนี้ -
- กำหนดขนาดรูปและปรับช่องว่างภายในระหว่างและรอบๆ แผนผังย่อย
- สร้าง x, y และ z จุดข้อมูลโดยใช้ตัวเลข
- พล็อต x, y และ s โดยใช้ scatter() วิธีการ
- ตั้งค่าป้ายกำกับแกน X และ Y
- วางคำอธิบายที่ด้านซ้ายบนของโครงเรื่อง
- หากต้องการแสดงรูป ให้ใช้ show() วิธีการ
ตัวอย่าง
import matplotlib.pyplot as plt
import numpy as np
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
x = np.arange(0.0, 50.0, 2.0)
y = x ** 1.3 + np.random.rand(*x.shape) * 30.0
s = np.random.rand(*x.shape) * 800 + 500
plt.scatter(x, y, s, c=x, alpha=0.5, marker=r'$\clubsuit$',
label="Legend", cmap="plasma")
plt.xlabel("X-Axis")
plt.ylabel("Y-Axis")
plt.legend(loc='upper left')
plt.show() ผลลัพธ์
