Legend with location set to 'best' collides with the title when the titles is moved down

Hi:

I’m adjusting the y-position of a plot title. Then, I add a legend with loc set to ‘best’. However, the legend is placed on top of the title.

The following code demonstrates the issue:

import matplotlib.pyplot as plt

plt.close('all')
plt.plot((1,2,3), label='Just a very long legend')
plt.title('Just a very long title 1234567890', y=0.9)
plt.legend(loc='best')
plt.show()

Is this a bug in legend, or am I missing something? Any advice on how to place the legend using loc=best without colliding with the title?

Hi @aweinstein, what version of Matplotlib are you using? There was a bugfix in v3.9 to make loc=best work with text: Fixed legend with legend location "best" when legend overlaps shaded area and text by alanlau28 · Pull Request #27469 · matplotlib/matplotlib · GitHub

Thank you, @rcomer, for your answer. I just updated Matplotlib to the latest version (3.9.4) and got the same result.

Do you think I should report a bug?

I reported a bug about this issue: