Closed
Description
Bug summary
When using the fill_between
function in matplotlib with a legend and specifying the legend location as "best", the legend is not taking into account the shaded area and may overlap with it.
Code for reproduction
import matplotlib.pyplot as plt
import numpy as np
# Example data
x = np.linspace(0, 5, 100)
y1 = 0.5 * np.exp(x) - 1
y2 = 2 * np.exp(x) + 1
# Plotting shaded area
plt.fill_between(x, y1, y2, color='gray', alpha=0.5, label='Shaded Area')
# Set y-axis limit
plt.ylim(-10, 100)
# Adding legend with location "best"
plt.legend(loc='best')
# Show the plot
plt.show()
Actual outcome
Expected outcome
Additional information
No response
Operating system
Windows 11
Matplotlib Version
3.8.0
Matplotlib Backend
module://backend_interagg
Python version
Python 3.11.5
Jupyter version
No response
Installation
conda