Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change pandas plot background color

Is it possible to change the background in a pandas chart?

I would like to change the background from white and the line to orange but I cannot find any documentation to do that.

I am using the pandas as follows:

import pandas.io.data as web
import numpy as np

gs = web.get_data_yahoo('gs')['Close']
gs = gs.pct_change()
gs.plot()

Is it possible to change the background to black or any other color?

like image 220
Uninvited Guest Avatar asked Apr 17 '14 01:04

Uninvited Guest


People also ask

How do you change the background color of a plot?

set_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.

How do I change the background color in pandas?

You can change the background color with ax. set_axis_bgcolor , but it will only change the area inside of the plot. This is useful when you have multiple plots in the same figure (a.k.a. multiple charts in the same image) but most of the time is just a headache.


1 Answers

plot() in pandas are build on matplotlib. The right way is just to access the plot axes object and change its bgcolor: change the lastlines to:

P=gs.plot()
P.set_axis_bgcolor('g') #or any HTML colorcode, (R,G,B) tuple, (R,G,B,A) tuple, etcetc.

enter image description here

like image 176
CT Zhu Avatar answered Oct 25 '22 17:10

CT Zhu