6

I am using matplotlibs ggplot style for plotting and want to overide only specific standard parameters such as the color of the xticklabels, grid background color and linewidth.

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()

returns: enter image description here

I know I can set single properties for axes-objects like this:

ax.set_axis_bgcolor('red')

But how can I override the default propertiers (e.g. label-color, background color and linewidth to have them in all plots?

Thanks in advance!

1 Answer 1

12

You could use rcParams to set parameters globally. 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

3
  • Perfect, thanks! Is there any way to globally change the axis label color? Feb 5, 2016 at 12:42
  • in the link from my answer it shows everything you can change. for axis labels, you can use plt.rcParams['axes.labelcolor']='r'. Not sure if you can change x and y separately
    – tmdavison
    Feb 5, 2016 at 12:55
  • Perfect. You saved my day. Thanks a lot!! Feb 5, 2016 at 13:02

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.