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

วิธีพลอตเส้นประ (Dashed Line) ใน Seaborn lineplot

Seaborn lineplot() รองรับพารามิเตอร์ linestyle เหมือน Matplotlib ตั้งค่า linestyle="dashed" (หรือ "--") เพื่อได้เส้นประ

ขั้นตอนการทำงาน

  1. ตั้งค่าขนาดรูปและเลย์เอาต์
  2. สร้างข้อมูล x, y
  3. พลอตด้วย sns.lineplot(x=x, y=y, linestyle="dashed")
  4. แสดงผล

ตัวอย่างโค้ด

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.rand(10)
y = np.random.rand(10)

ax = sns.lineplot(x=x, y=y, linestyle="dashed")
plt.show()

ผลลัพธ์

วิธีพลอตเส้นประ (Dashed Line) ใน Seaborn lineplot