seaborn.despine() loại bỏ các đường viền (spines) trên và phải của biểu đồ, tạo giao diện sạch, hiện đại (style "white" hoặc "ticks").
Ví dụ
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sb
def sine_plot(flip=1):
x = np.linspace(0, 14, 99)
for i in range(1, 5):
plt.plot(x, np.sin(x + i * .59) * (11 - i) * flip)
sb.set_style("white")
print("Đang vẽ dữ liệu...")
sine_plot()
sb.despine() # loại bỏ top và right spines
plt.show()
Giải thích
sb.set_style("white"): nền trắng, không lưới.sb.despine(): xóa top/right spines. Mặc định giữ bottom/left.- Tuỳ chọn:
despine(left=True, bottom=True)xóa tất cả 4 cạnh. despine(offset=10): đẩy axes ra xa khung một chút.
Kết hợp với style
"whitegrid": nền trắng + lưới ngang/dọc."ticks": có ticks trên mọi cạnh, despine gọn gàng."darkgrid": nền xám + lưới trắng (mặc định).