Seaborn plot two data sets on the same scatter plot

后端 未结 1 1779
你的背包
你的背包 2021-01-14 08:24

I have 2 data sets in Pandas Dataframe and I want to visualize them on the same scatter plot so I tried:

import matplotlib.pyplot as plt
import seaborn as sn         


        
相关标签:
1条回答
  • 2021-01-14 08:45

    The following should work in the latest version of seaborn (0.9.0)

    import matplotlib.pyplot as plt
    import seaborn as sns
    

    First we concatenate the two datasets into one and assign a dataset column which will allow us to preserve the information as to which row is from which dataset.

    concatenated = pd.concat([set1.assign(dataset='set1'), set2.assign(dataset='set2')])
    

    Then we use the sns.scatterplot function from the latest seaborn version (0.9.0) and via the style keyword argument set it so that the markers are based on the dataset column:

    sns.scatterplot(x='Std', y='ATR', data=concatenated,
                    hue='Asset Subclass', style='dataset')
    plt.show()
    
    0 讨论(0)
提交回复
热议问题