Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using plt.show() how can I define the background color?

Tags:

matplotlib

When I visualize a plot, the default background color is something like gray. I want to have a white end, like the one that I obtain when I save the plot. this is what I see with plt.show()

like image 435
heracho Avatar asked Sep 01 '25 00:09

heracho


1 Answers

Like any other patch, the figure itself has a set_facecolor() method.

fig = plt.figure()
fig.set_facecolor("w")

You may also directly use the facecolor argument of plt.figure()

fig = plt.figure(facecolor="w")

A third option is to set the respective rc Parameter. This can either be done in the top of the script

plt.rcParams["figure.facecolor"] = "w"

or by chaning the matplotlib rc file.

Note that from matplotlib version 2.0 on, the default facecolor for figures is actually white, so updating matplotlib is the fourth option available.

like image 184
ImportanceOfBeingErnest Avatar answered Sep 02 '25 19:09

ImportanceOfBeingErnest