ใช้เมธอด scatter เพื่อสร้างการกระจายร่วมแบบ Bivariate
ขั้นตอนการทำงาน
- กำหนดขนาดรูปภาพและปรับระยะห่างระหว่างและรอบๆ subplots
- สร้างข้อมูล x และ y ด้วย numpy
- สร้าง figure และชุด subplots
- พล็อต x และ y ด้วยเมธอด scatter()
- ใช้เมธอด show() เพื่อแสดงรูปภาพ
ตัวอย่างโค้ด
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()
ผลลัพธ์
