plt.text background alpha code example

Example 1: plt text matplotlib white background

import numpy as np
import matplotlib.pyplot as plt
plt.figure()
ax = plt.subplot(111)
plt.plot(np.linspace(1,0,1000))
t = plt.text(0.03,.95,'text',transform=ax.transAxes,backgroundcolor='0.75',alpha=.5)
plt.show()

Example 2: plt.text background alpha

plt_text = plt.text(
	0.5,  # x
    0.5,  # y
    'your text',  # text
    fontsize=30
)
plt_text.set_bbox(dict(
	facecolor='red',  # background color
    alpha=0.5,  # background alpha
    edgecolor='red'  # border color
))