Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> Python

Cách vẽ đường nét đứt (dashed line) trên Seaborn lineplot trong Matplotlib

Để vẽ đường nét đứt trên Seaborn lineplot, ta dùng tham số linestyle="dashed" trong lineplot().

Các bước thực hiện

  • Thiết lập kích thước hình và khoảng đệm.
  • Tạo dữ liệu x, y bằng NumPy.
  • Gọi lineplot() với x, y và linestyle="dashed".
  • Hiển thị bằng show().

Ví dụ

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()

Kết quả

Cách vẽ đường nét đứt (dashed line) trên Seaborn lineplot trong Matplotlib