I'm plotting some numbers from my pandas dataframes df1
and df2
using seaborn and subplots, and would like to add an annotated line showing the median value for a column from each dataframe on the subplots.
I am able to get a line drawn on the median using axvline
in the following code, but not sure how to annotate the drawn line to display the actual median value:
df1median = df1['values'].median()
df2median = df2['values'].median()
fig, axes = plt.subplots(1,2)
sns.kdeplot(data=df1, x='values', ax=axes[0])
axes[0].axvline(df1median)
sns.kdeplot(data=df2, x='values', ax=axes[1])
axes[1].axvline(df2median)
I can annotate manually by using plt.text
and setting the position manually, but would like a way to annotate the drawn axvline on each subplot directly. Is this possible?