pandas 更改熊猫绘图背景颜色

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23123272/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 21:56:18  来源:igfitidea点击:

Change pandas plot background color

pythoncolorsbackgroundmatplotlibpandas

提问by Uninvited Guest

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

是否可以更改Pandas图表中的背景?

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:

我使用Pandas如下:

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?

是否可以将背景更改为黑色或任何其他颜色?

回答by CT Zhu

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

plot()pandas建立在matplotlib. 正确的方法是访问绘图轴对象并更改其 bgcolor:将最后一行更改为:

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

在此处输入图片说明