เมื่อใช้ plt.subplot() พร้อม sharey (หรือ sharex) ตามค่าเริ่มต้น tick labels จะแสดงบน axes ทุกตัว ไม่ซ่อนอัตโนมัติเหมือน subplots() ทำให้เห็นป้ายทุกซับพลอต
ขั้นตอนการทำงาน
- ตั้งค่าขนาดรูปและเลย์เอาต์
- สร้าง ax1 ด้วย
plt.subplot(1, 2, 1) - สร้าง ax2 ด้วย
plt.subplot(1, 2, 2, sharey=ax1) - พลอตข้อมูลทั้งสอง axes
- แสดงผล - tick labels แสดงทั้งคู่
ตัวอย่างโค้ด
from matplotlib import pyplot as plt
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
ax1 = plt.subplot(1, 2, 1)
ax1.plot([1, 4, 9])
ax2 = plt.subplot(1, 2, 2, sharey=ax1)
ax2.plot([1, 8, 27])
plt.show()
ผลลัพธ์
