I have created a boxplot using pandas dataframe and now I want to mark specific values in the same plot, with an "X" (hopefully in screaming red!).
Some data:
df = pd.DataFrame(
[
[2, 4, 5, 6, 1],
[4, 5, 6, 7, 2],
[5, 4, 5, 5, 1],
[10, 4, 7, 8, 2],
[9, 3, 4, 6, 2],
[3, 3, 4, 4, 1]
], columns=['a1', 'a2', 'a3', 'a4', 'b'])
mark_values = pd.DataFrame(
[
[2,1],
[8.25,2]
], columns=['a1', 'b'])
df_long = pd.melt(df, "b", var_name="a", value_name="c")
g = sns.boxplot(x='c', y='a', hue='b', data=df_long,
palette=sns.color_palette("Blues_d"), orient='h')
sns.despine(left=True)
This generates a boxplot. I would now like to add markers as red crosses, e.g. marking the category a1, subgroup 1 with an X at "4", and subgroup 2 with an X at "8.25" etc. and still keep my nice boxplots.
The values that would be marked should be defined and stored as in the dataframe mark_values
defined above. As in the example:
mark_values
Out[1]:
a1 b
0 4.00 1
1 8.25 2
Any easy solution to this?
Thanks