简体   繁体   中英

2 line plot using seaborn

I want to plot this array. I am using seaborn to do that. I used

import seaborn as sns
sns.set_style('whitegrid')
sns.kdeplot(data= score_for_modelA[:,0])

But the above one only gives for column 1. My scores are in column 1 and 2 and I want both of them plotted in the same graph. The sample data is like this: array ([[0.67,0.33],[0.45,0.55],......,[0.81,0.19]]

You can try putting them into a data frame first, with the proper column names, for example:

import seaborn as sns
import numpy as np
import pandas as pd

score_for_modelA = np.random.normal(0,1,(50,2))
pd.DataFrame(score_for_modelA,columns = ['col1','col2'])

When you plot, it's a matter of melting it:

sns.set_style('whitegrid')
sns.kdeplot(data= pd.DataFrame(score_for_modelA,columns = ['col1','col2']).melt(),
            hue = "variable",x = "value")

在此处输入图像描述

As pointed out by @JohanC, if you just want to plot all the columns, you can do without the melt:

sns.kdeplot(data= pd.DataFrame(score_for_modelA,columns = ['col1','col2']))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM