จำนวน مختلط a + bj มีส่วนจริง (real) และจินตภาพ (imag) ใช้ data.real และ data.imag เป็นพิกัด x, y ใน ax.scatter() สร้าง Argand diagram ได้ง่าย
ขั้นตอนการทำงาน
- ตั้งค่าขนาดรูปและเลย์เอาต์
- สร้างข้อมูล complex แบบสุ่ม:
np.random.rand(10) + 1j*np.random.rand(10) - สร้าง figure และ axes
- พลอต scatter:
ax.scatter(data.real, data.imag, c=data.real, cmap='RdYlBu_r') - แสดงผล
ตัวอย่างโค้ด
import numpy as np
from matplotlib import pyplot as plt
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
data = np.random.rand(10) + 1j*np.random.rand(10)
fig, ax = plt.subplots()
ax.scatter(data.real, data.imag, c=data.real, cmap="RdYlBu_r")
plt.show()
ผลลัพธ์
