[英]How to combine two jointplots with different colors
您需要合並您的數據框,添加色調列。 這是一個從一些測試數據開始的例子。 請注意,當使用多個分布時,為了使 plot 更具可讀性,seaborn 自動將邊緣圖從直方圖更改為 kdeplots。
import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
import numpy as np
np.random.seed(20221129)
dfb = pd.DataFrame({'col4': np.random.randn(1000).cumsum(),
'col6': np.random.randn(1000).cumsum()})
dfr = pd.DataFrame({'col4': np.random.randn(100).cumsum(),
'col6': np.random.randn(100).cumsum()})
df_merged = pd.DataFrame({'col4': pd.concat([dfb['col4'], dfr['col4']]),
'col6': pd.concat([dfb['col6'], dfr['col6']]),
'origin': ['dfb'] * len(dfb) + ['dfr'] * len(dfr)}).reset_index()
sns.jointplot(x='col4', y='col6', hue='origin', data=df_merged, palette=["blue", "red"])
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.