I have the following plot in seaborn:
df = pandas.DataFrame({"sample": ["X", "X", "X", "Y", "Y", "Y"],
"value": [0.2, 0.3, 0.4, 0.7, 0.75, 0.8],
"rep": ["a", "b", "c", "a", "b", "c"]})
plt.figure()
ax = sns.stripplot(x="sample", y="value", edgecolor="none",
hue="sample", palette="Set1", data=df)
# how to plot median line?
plt.show()
It plots the points in gray scale colors instead of using Set1
and only shows X
in the legend and not Y
:
I also want to add a horizontal line at the median for X
and Y
. how can this be done? factorplot
doesn't appear to have a horizontal line option.
You may plot lines by using matplolib. Pandas may calculate medians value for your dataset. I use seaborn 0.7.0 in this example:
We can limit the width of each median line to its respective column by looping through the Axes ticks and ticklabels after generating the stripplot. This also enables the code to operate independent of the number of samples (columns) to be plotted.
seaborn stripplot with median lines drawn: