Setup font size and other groups in matplotlib
There are 3 equivalent ways to setup rc file.
matplotlib.pyplot.rc
import matplotlib.pyplot as plt
plt.rc('lines', linewidth=2, color='r')
matplotlib.rc
import matplotlib as mpl
mpl.rc('lines', linewidth=2, color='r')
matplotlib.rcParams
import matplotlib as mpl
mpl.rcParams['lines.linewidth'] = 2
mpl.rcParams['lines.color'] = 'r'
setup font size
import matplotlib.pyplot as plt
sfs, mfs, lfs = 8, 10, 12
plt.rc('font', size=sfs)
plt.rc('axes', titlesize=sfs, labelsize=mfs)
plt.rc('xtick', labelsize=sfs)
plt.rc('ytick', labelsize=sfs)
plt.rc('legend', fontsize=sfs)
plt.rc('figure', titlesize=lfs)
my custom style
import matplotlib.pyplot as plt
sfs, mfs, lfs = 8, 10, 12 #in points
plt.rc('figure', figsize=[7, 4], titlesize=lfs) #width, height in inches
plt.rc('savefig', dpi=300)
plt.rc('lines', linewidth=1.0, markersize=5.0) #in points
plt.rc('font', family='Times New Roman', size=sfs)
plt.rc('axes', titlesize=sfs, labelsize=mfs)
plt.rc('xtick', labelsize=sfs)
plt.rc('ytick', labelsize=sfs)
plt.rc('legend', fontsize=sfs)
plt.rc('figure', titlesize=lfs)
Reference:
- How to change the font size on a matplotlib plot
- matplotlib.pyplot.rc
- matplotlib.rc
- matplotlib.rcParams
Share on: