Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove gray border from matplotlib

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()

my image

Thank you!

like image 836
hobscrk777 Avatar asked Jan 12 '23 02:01

hobscrk777


1 Answers

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()

enter image description here

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.

like image 199
mwaskom Avatar answered Jan 22 '23 19:01

mwaskom