In the example below, how can I change the background color of "Title" to be red (with alpha=.5), not the font color of "Title"?
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.plot([1,2,3,], [1,2,3], label='Series')
legend = ax.legend(title='Title')
# Access to the legend title box adapted from
# https://stackoverflow.com/a/63570572
legend._legend_title_box._text.set_color('red')

You can change the color of the bounding box of the title text:
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.plot([1, 2, 3, ], [1, 2, 3], label='Series')
legend = ax.legend(title='Title')
legend._legend_title_box._text.set_bbox(dict(facecolor='red', alpha=0.3, lw=0))
plt.show()

PS: For the red background to span the entire width of the legend frame, you could pad the title with whitespace, as proposed by Trenton Mckinney. E.g.
legend = ax.legend(title=f'{"Title": ^15}', frameon=False)

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With