How to remove gray border with matplotlib

I am trying to understand matplotlib, but for my life I cannot get rid of this gray border around the plot.

My code is very simple. I was looking through the matplotlib documentation, but unfortunately I can not find anything on how to change the background color. Can anybody 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!

+4
source share
1 answer

There are many ways. The most directly related to the style of code you have will 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 graphs in the session by doing

import matplotlib as mpl
mpl.rc("figure", facecolor="white")

Or for all graphs in all sessions, setting figure.facecolorto a file matplotlibrc.

+7
source

Source: https://habr.com/ru/post/1529332/


All Articles