การปรับแต่งป้ายแกนใน Seaborn jointplot สามารถทำได้โดยใช้เมธอด set_xlabel() และ set_ylabel() ของออบเจ็กต์ JointGrid ที่คืนค่ากลับมา นอกจากนี้ยังรองรับรูปแบบ LaTeX สำหรับการแสดงสูตรคณิตศาสตร์หรือข้อความแบบตัวหนาได้
ขั้นตอนการทำงาน
- ตั้งค่าขนาดรูปและระยะห่างระหว่างซับพลอตด้วย
plt.rcParams - สร้างข้อมูล x และ y ด้วย NumPy
- สร้าง jointplot ด้วย
sns.jointplot() - ปรับแต่งป้ายแกน x ด้วย
ax_joint.set_xlabel()(รองรับ LaTeX) - แสดงผลด้วย
plt.show()
ตัวอย่างโค้ด
import seaborn as sns
import numpy as np
from matplotlib import pyplot as plt
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
x = np.random.randn(1000)
y = 0.2 * np.random.randn(1000) + 0.5
h = sns.jointplot(x, y, height=3.50)
h.ax_joint.set_xlabel(r'$\bf{X-Axis\ Label}$')
plt.show()
ผลลัพธ์
