Để vẽ jointplot hoặc jointgrid không vuông trong Seaborn, ta dùng set_figwidth() và set_figheight().
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, y bằng numpy.
- Tạo DataFrame hai cột.
- Dùng jointplot() để vẽ.
- Đặt chiều rộng và cao figure để làm cho nó không vuông.
- Hiển thị hình 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))
jp = sns.jointplot(x="x", y="y", data=df, height=3.5,
joint_kws={'color': 'red'})
jp.fig.set_figwidth(7.50)
jp.fig.set_figheight(3.50)
plt.show()
Kết quả
