I have a contour plot for which I would like to use a legend that has a solid white background, so that the legend is readable over the contour lines.
My problem is that when I change the facecolor, nothing happens. I've also tried changing the framealpha, but nothing happens. Here is a toy code, and the resulting figure. How do I change the facecolor of my legend so that the legend is readable over the contours?
import numpy as np
import matplotlib.pyplot as plt
# Create data
delta = 0.025
x = np.arange(-1.0, 1.0, delta)
y = np.arange(-1.0, 1.0, delta)
X, Y = np.meshgrid(x, y)
Z = np.exp(-X**2 - Y**3)
# Plot data
fig, ax = plt.subplots()
CS = ax.contour(X, Y, Z)
# Create legend.
# Code modified from https://github.com/matplotlib/matplotlib/issues/11134
CS_elem,_ = CS.legend_elements()
ax.legend(CS_elem, ['-X**2 - Y**3'], loc='lower left',facecolor="blue", framealpha=1)