Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python

วิธีสร้าง multiple series scatter plots เชื่อมจุดด้วย seaborn

ในการสร้าง multiple series scatter plots เชื่อมจุดด้วย seaborn สามารถทำตามขั้นตอนดังนี้:

ขั้นตอน

  • ตั้งค่าขนาดรูปและปรับ padding ระหว่างและรอบ subplots

  • สร้าง Pandas data frame ข้อมูลตาราง 2 มิติ

  • Multi-plot grid สำหรับ plotting conditional relationships

  • Apply plotting function ให้แต่ละ facet subset ของข้อมูล

  • วาด scatter และ data points ด้วย x และ y

  • แสดงรูปด้วยเมธอด show()

ตัวอย่าง

import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
df = pd.DataFrame({"x": [4, 6, 7, 1, 8], "y": [1, 5, 7, 8, 1]})
g = sns.FacetGrid(df, hue="x", height=3.5)
g.map(plt.scatter, "x", "y")
g.map(plt.plot, "x", "y")
plt.show()

ผลลัพธ์

จะแสดง scatter points กลุ่มตาม hue x พร้อมเส้นเชื่อม

วิธีสร้าง multiple series scatter plots เชื่อมจุดด้วย seaborn