Matplotlib:覆盖“ggplot”默认样式属性

时间:2016-02-05 11:40:47

标签: python pandas matplotlib python-ggplot

我使用matplotlibs ggplot 样式进行绘图,并且只想覆盖特定的标准参数,例如xticklabels的颜色,网格背景颜色和线宽。

import numpy as np
import pandas as pd
import matplotlib

# changing matplotlib the default style
matplotlib.style.use('ggplot')

# dataframe plot
df = pd.DataFrame(np.random.randn(36, 3))
df.plot()

返回: enter image description here

我知道我可以为这样的轴对象设置单个属性:

ax.set_axis_bgcolor('red')

但是如何覆盖默认属性(例如标签颜色,背景颜色和线宽以将它们放在所有图中?

提前致谢!

1 个答案:

答案 0 :(得分:7)

您可以使用rcParams全局设置参数。 e.g。

import numpy as np
import pandas as pd
import matplotlib
import matplotlib.pyplot as plt

# changing matplotlib the default style
matplotlib.style.use('ggplot')

plt.rcParams['lines.linewidth']=3
plt.rcParams['axes.facecolor']='b'
plt.rcParams['xtick.color']='r'

# dataframe plot
df = pd.DataFrame(np.random.randn(36, 3))
df.plot()

plt.show()

enter image description here