I'm trying to understand matplotlib, but I can't for the life of me get rid of this gray border around the plot.
My code is super simple. I've been looking through the matplotlib documentation, but frustratingly enough I can't find anything about how to change the background color. Can someone please help?
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0,10)
y = np.linspace(0,10)
plt.plot(x,y)
plt.show()
Thank you!
There are quite a few ways. The most directly related to the style of code you have would be
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0, 10)
y = np.linspace(0, 10)
plt.figure(facecolor="white")
plt.plot(x, y)
plt.show()
This can also be set for all plots in your session by doing
import matplotlib as mpl
mpl.rc("figure", facecolor="white")
Or for all plots in all sessions by setting the figure.facecolor
in a matplotlibrc
file.
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