Plot 2 ชุดข้อมูลที่มีความยาว Array ต่างกัน โดยระบุ X, Y แยกกันสำหรับแต่ละชุด
ตัวอย่างโค้ด
import numpy as np
import matplotlib.pyplot as plt
plt.rcParams["figure.figsize"] = [7.00, 3.50]
plt.rcParams["figure.autolayout"] = True
y1 = (np.random.random(100) - 0.5).cumsum()
y2 = y1.reshape(-1, 10).mean(axis=1) # Downsample 10x
x1 = np.linspace(0, 1, 100)
x2 = np.linspace(0, 1, 10)
plt.plot(x1, y1)
plt.plot(x2, y2)
plt.show()
คำอธิบาย
y1: Random Walk 100 จุดy2: Reshape เป็น (10,10) หาระดับ Mean แถว -> 10 จุด (Downsample)x1: 100 จุด,x2: 10 จุด (ช่วง 0-1 เดียวกัน)plt.plot(x1, y1)และplt.plot(x2, y2)วาดบน Figure เดียวกัน- Matplotlib จัดการ Scale อัตโนมัติ