Cord Kaldemeyer
Cord Kaldemeyer

Reputation: 6907

Matplotlib: Overriding "ggplot" default style properties

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!

Upvotes: 6

Views: 6921

Answers (1)

tmdavison
tmdavison

Reputation: 69183

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

Upvotes: 12

Related Questions