To plot a Seaborn boxplot with mean instead of median in Python, you can modify the underlying matplotlib function. Here's an example using the tips
dataset:
main.py601 chars21 lines
In this code, we define a custom function boxplot_mean
that extends the functionality of sns.boxplot
. Inside this function, we calculate the mean values using groupby
and mean
functions. Then, we iterate over the x-ticks of the plot and use ax.text
to annotate the mean values on the plot.
This will create a boxplot with mean values instead of median. You can customize further by modifying the aesthetics and labels of the plot.
gistlibby LogSnag