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

Đổi màu đường hồi quy trong Seaborn jointplot linear regression

Để thay đổi màu đường hồi quy (regression line) trong sns.jointplot(kind='reg'), dùng tham số joint_kws={'color': 'green'}.

Các bước

  • Thiết lập figure size và autolayout.
  • Tạo dữ liệu X, Y và DataFrame.
  • Gọi sns.jointplot(x="x", y="y", data=df, kind='reg', joint_kws={'color':'green'}).
  • Hiển thị bằng show().

Ví dụ

import seaborn as sns
import numpy as np
from matplotlib import pyplot as plt
import pandas as pd

plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True

X = np.random.randn(1000,)
Y = 0.2 * np.random.randn(1000) + 0.5
df = pd.DataFrame(dict(x=X, y=Y))
g = sns.jointplot(x="x", y="y", data=df, kind='reg', height=3.5, joint_kws={'color':'green'})
plt.show()

Kết quả

Đổi màu đường hồi quy trong Seaborn jointplot linear regression