1

Currently displaying some data with Seaborn / Pandas. I'm looking to overlay the mean of each category (x=ks2) - but can't figure out how to do this with Seaborn.

I can remove the inner="box" - but want to replace that with a marker for the mean of each category.

Ideally, then link each mean calculated...

Any pointers greatly received. Cheers

Science.csv has 9k+ entries

import seaborn as sns
import pandas as pd
import matplotlib.pyplot as plt

sns.set(style="whitegrid", palette="pastel", color_codes=True)

# Load the dataset
# df = pd.read_csv("science.csv")  << loaded from csv

df = pd.DataFrame({'ks2': [1, 1, 2,3,3,4], 
                   'science': [40, 50, 34,20,0,44]})


# Draw a nested violinplot and split the violins for easier comparison
sns.violinplot(x="ks2", y="science", data=df, split=True,
               inner="box",linewidth=2)
sns.despine(left=True)
plt.savefig('plot.png')

NimueSTEM
  • 193
  • 2
  • 13
  • 1
    Interesting question. Please post data in body of question as we do not have access to `science.csv`. See [How to make good reproducible pandas examples](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples). – Parfait Feb 11 '20 at 14:34
  • @Parfait >>done. ks2 can actually be 1 - 6 (int). science can be 0-50 (int). Will ammend to add a dataframe... – NimueSTEM Feb 11 '20 at 14:39

1 Answers1

2

try:

from numpy import mean

then overlay sns.pointplot with estimator=mean

sns.pointplot(x = 'ks2', y='science', data=df, estimator=mean)

then play with linestyles

GLarose
  • 171
  • 1
  • 9