ขั้นตอนการทำงาน
- กำหนดขนาดรูปภาพและปรับระยะห่างระหว่างและรอบๆ subplots
- สร้าง DataFrame ของ Pandas พร้อมคีย์ X-axis และ Y-axis
- พล็อตตัวแปรอิสระตัวเลขพร้อมโมเดลถดถอย
- ใช้เมธอด show() เพื่อแสดงรูปภาพ
ตัวอย่างโค้ด
import pandas
import matplotlib.pylab as plt
import seaborn as sns
import numpy as np
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
df = pandas.DataFrame({"X-Axis": [np.random.randint(5) for i in range(10)], "Y-Axis": [np.random.randint(5) for i in range(10)]})
sns.regplot(x='X-Axis', y='Y-Axis', data=df, scatter_kws={"color": "red"}, line_kws={"color": "green"})
plt.show()
ผลลัพธ์
