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

Cách vẽ jointplot với tham số 'hue' trong Seaborn? (Matplotlib)

Để vẽ jointplot với tham số hue trong Seaborn:

Các bước

  • Thiết lập kích thước hình và điều chỉnh khoảng đệm subplot.
  • Tạo điểm dữ liệu x bằng numpy.
  • Tạo dictionary dữ liệu đường cong.
  • Tạo DataFrame dữ liệu bảng.
  • Vẽ jointplot bằng jointplot().
  • Hiển thị hình bằng show().

Ví dụ

from matplotlib import pyplot as plt
import pandas as pd
import seaborn as sns
import numpy as np
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
x = np.linspace(0, 1, 5)
d = {
    'y=sin(x)': np.sin(x),
    'y=cos(x)': np.cos(x),
    'y=x': x,
}
df = pd.DataFrame(d)
jg = sns.jointplot(data=df, x="y=sin(x)", y="y=cos(x)",
                    height=3.5, hue="y=x")
plt.show()

Kết quả

Cách vẽ jointplot với tham số  hue  trong Seaborn? (Matplotlib)