Matplotlib text transparency

matplotlib, python

Solution

You can set alpha when using `annotate` to add the text to your figure.

Before:

import matplotlib.pyplot as plt

fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)

ax.annotate("TESTING", xy=(.5, .5), xytext=(.5, .5))

plt.show()

After:

import matplotlib.pyplot as plt

fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)

text = ax.annotate("TESTING", xy=(.5, .5), xytext=(.5, .5))

text.set_alpha(.4)

plt.show()

Problem

I was wondering if it is possible to change the transparency of a text in Matplotlib. `set_alpha` does not function and in the documentation I couldn't find anything relevant. Are there may be any workarounds? I want to connect it to a pick_event. EDIT: I was actually trying to change the transparency of a legend-text. Although I tried to solve the issue with `set_alpha`, I have overseen that I was trying to modify the transparency of a list and hence I couldn't succeed. To sum up, as can be seen from answers, the transparency can be modified with `set_alpha`

Original source