The following question explains how to change the background color of a legend: matplotlib legend background color. However, if I use seaborn this does not work. Is there a way to do this?
import matplotlib.pyplot as plt
import numpy as np
a = np.random.rand(10,1)
plt.plot(a, label='label')
legend = plt.legend()
frame = legend.get_frame()
frame.set_facecolor('green')
plt.show()
import seaborn as sns
plt.plot(a, label='label')
legend = plt.legend()
frame = legend.get_frame()
frame.set_facecolor('green')
plt.show()
seaborn turns the legend frame off by default, if you want to customize how the frame looks, I think you'll need to add
frameon=True
when you callplt.legend
.