python plot text in box code example
Example 1: how to display text on boxplot in python
import seaborn as sns
sns.set_style("whitegrid")
tips = sns.load_dataset("tips")
box_plot = sns.boxplot(x="day",y="total_bill",data=tips)
medians = tips.groupby(['day'])['total_bill'].median()
vertical_offset = tips['total_bill'].median() * 0.05
for xtick in box_plot.get_xticks():
box_plot.text(xtick,medians[xtick] + vertical_offset,medians[xtick],
horizontalalignment='center',size='x-small',color='w',weight='semibold')
Example 2: plt.text background alpha
plt_text = plt.text(
0.5,
0.5,
'your text',
fontsize=30
)
plt_text.set_bbox(dict(
facecolor='red',
alpha=0.5,
edgecolor='red'
))