0

I am using matplotlib.pyplot to plot a histogram and can not figure out how to change the background of the plot.

import matplotlib.pyplot as plt
y,x,mean=plt.hist(dataset.Y_Pos_Pivot,25,edgecolor = 'black', fill=True,facecolor='Blue',cumulative=False)
plt.show()

Histogram

Ryan Reed
  • 3
  • 5

2 Answers2

1

For example for green background use:

import matplotlib.pyplot as plt

fig, ax = plt.subplots()
y,x,mean=plt.hist(nlvng[0],25,edgecolor = 'black', fill=True,facecolor='Blue',cumulative=False)
ax.set_facecolor("g")
plt.show()

Setting of axis ax property is needed.

ipj
  • 3,488
  • 1
  • 14
  • 18
  • How can you change the color of the outside of the graph? Thank you for your help – Ryan Reed Jul 13 '20 at 15:22
  • Outside graph, look here: https://stackoverflow.com/questions/14088687/how-to-change-plot-background-color – ipj Jul 13 '20 at 15:31
0

Have a look to this: How to change plot background color?

In matplotlib, you can use "set_facecolor" in a subplot before you populate it with the histogram.

import matplotlib.pyplot as plt
fig,ax = plt.subplots(1,1) #Creates one figure with one subplot in one column
ax.set_facecolor('gray') #Set the background color to blue
ax = plt.hist(<Your data>) #Sets the subplot to be the histogram you want