0

I am trying to create one seaborn stripplot from 4 lists of data (they are of different length). Each list contains numbers between 0 to 1, and I wish each of those number to be a dot in the plot, while each list would be a different "x axis category" on the plot.

for instance if this is my data-

pn=[0.70604173074, 0.7019483995600001, 0.70271586578, 0.6977801500400002] 

tc=[0.49288115891999995, 0.7288539852599999, 0.6258675808399999, 0.33007094978000007, 0.45538473337999996, 0.5849680367, 0.5151045102999999, 0.78011459304, 0.52564381038] 

pc=[0.6286486934200001, 0.6450898248599999, 0.45266545178, 0.54746642074, 0.36717567197999995, 0.6974179308799999] 

tn= [0.7776927921000001, 0.7845524455400001]

I want to plot those 4 lists on one stripplot like this- example just instead of the days I want my lists names and I want the Y axis to range from 0 to 1 (represents my numbers range).

Unfortunately I am only succeeding plotting them randomly, not sorted on the X axis by the different lists

I'd also like to add box plots to to each list if possible.

Any advice would be appreciated. Thank you.

Zephyr
  • 11,891
  • 53
  • 45
  • 80
Dolev
  • 9
  • 2

1 Answers1

2

Use DataFrame.from_dict with orient='index' to put your data into a df:

df = pd.DataFrame.from_dict(
    data=dict(pn=pn, tc=tc, pc=pc, tn=tn),
    orient='index',
).T

#          pn        tc        pc        tn
# 0  0.706042  0.492881  0.628649  0.777693
# 1  0.701948  0.728854  0.645090  0.784552
# 2  0.702716  0.625868  0.452665       NaN
# 3  0.697780  0.330071  0.547466       NaN
# 4       NaN  0.455385  0.367176       NaN
# 5       NaN  0.584968  0.697418       NaN
# 6       NaN  0.515105       NaN       NaN
# 7       NaN  0.780115       NaN       NaN
# 8       NaN  0.525644       NaN       NaN

This format works directly with sns.stripplot:

ax = sns.stripplot(data=df)
ax.set_ylim(0, 1)

stripplot output

It also works with sns.boxplot, so you can overlay it on the same ax:

ax = sns.stripplot(data=df)
sns.boxplot(data=df, saturation=0.4, ax=ax)
ax.set_ylim(0, 1)

boxplot output

tdy
  • 36,675
  • 19
  • 86
  • 83