Matplotlib Regular Config

默认字体

1
2
3
4
import matplotlib.pyplot as plt

# alter the default font of figure
plt.rc('font', family='Times New Roman')

画图设置

1
2
3
4
# alter the nums of column and row of subplot
plt.subplots(nrows=3, ncols=3, figsize=(6, 6))
# alter the distance between closing two subplots
plt.subplots_adjust(left=0.2, right=0.85, top=0.9, bottom=0.15, wspace=0.01, hspace=0.1)

坐标轴

1
2
3
4
5
6
7
8
# set font size of ticks
plt.xticks(fontsize=16)
plt.yticks(fontsize=16)
plt.tick_params(labelsize=16)

# Alter display distance of X tick to times of 0.5(ie,0.5, 1.0, 1.5, 2.0, ...)
from matplotlib.pyplot import MultipleLocator
plt.gca().xaxis.set_major_locator(MultipleLocator(0.5))

图例

1
2
# Alter the size of legend, whether frameon is needed, adjust the accuracy location 
plt.legend(fontsize='x-large', loc=0, frameon=False, bbox_to_anchor=(0.575, 0.38))

Cheatsheets

sample