Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Modify background color in Pandas plot?

I'm currently using Pandas direct plot (df.plot) in Python 2.7. It has worked great except it leaves me with a gray background. Is it possible to modify this color (eg. set it to white?)

Thanks.

like image 896
ForeignVolatility Avatar asked Jan 15 '18 13:01

ForeignVolatility


People also ask

How do you change the background color of a plot in Python?

MatPlotLib with Python To change the axes background color, we can use set_facecolor() method.

How do you change the background of a chart in Python?

Matplotlib change background color inner and outer colorset_facecolor() method is used to change the inner background color of the plot. figure(facecolor='color') method is used to change the outer background color of the plot. In the above example, we have change both an inner and outer color of background of plot.

How do you change the background of a scatter plot in Python?

The easiest way to change the background color of a plot in Matplotlib is to use the set_facecolor() argument.


1 Answers

Sure

You can use the ax object the plot function returns.

my_df = pd.DataFrame({'A': range(0, 100), 'B': np.random.uniform(1, 100, 100)})
ax = my_df.plot(kind='scatter', x='A', y='B')
ax.set_facecolor('black')
like image 130
yoav_aaa Avatar answered Oct 12 '22 12:10

yoav_aaa