簡體   English   中英

如何結合兩個具有不同 colors 的聯合圖

[英]How to combine two jointplots with different colors

我希望將兩個聯合圖繪制在一起,而不是繪制在不同的圖形上。 我怎樣才能做到這一點?

我試過了

sns.jointplot(column_headers[4],column_headers[6],data=df,color="blue")
sns.jointplot(column_headers[4],column_headers[6],data=typesatt[0],color="red")

它給了我兩個不同的數字

在此處輸入圖像描述 在此處輸入圖像描述

您需要合並您的數據框,添加色調列。 這是一個從一些測試數據開始的例子。 請注意,當使用多個分布時,為了使 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"])

來自兩個數據框的 sns.jointplot

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM