Matplotlib: overriding default ggplot style properties

I use the matplotlibs ggplot style to build and want to override only certain standard options, such as xticklabels color, grid background color and line width.

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 that I can set single properties for object axes like this:

 ax.set_axis_bgcolor('red') 

But how can I override the default properties (e.g. label color, background color and line width so that they are in all graphs?

Thanks in advance!

+5
source share
1 answer

You can use rcParams to set parameters around the world. eg.

 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

+5
source

Source: https://habr.com/ru/post/1242370/


All Articles