13

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?

1 Answer 1

14

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

Sign up to request clarification or add additional context in comments.

1 Comment

Seems to be deprecated. Use P.set_facecolor('g') instead.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.