How can I make only part of the text in an annotation box transparent?
As an example, this code (adapted from here)
import numpy as np
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111)
t = np.arange(0.0, 5.0, 0.01)
s = np.cos(2*np.pi*t)
line, = ax.plot(t, s, lw=2)
ax.annotate('local max (transparent)', xy=(2, 1), xytext=(3, 1.5),
arrowprops=dict(facecolor='black', shrink=0.05),
)
ax.set_ylim(-2,2)
plt.show()
produces the following output:
I would like the word transparent in the annotation box to be slightly transparent. However, the rest of the text (local maximum) should be displayed as it currently is.