In [ ]:
%matplotlib inline
In [ ]:
# 全局配置
import matplotlib
import matplotlib.pyplot as plt
# rc: run configure
In [ ]:
# 全局配置文件
print(matplotlib.matplotlib_fname())
In [ ]:
# 修改方式一
matplotlib.rcParams['lines.linewidth'] = 2
matplotlib.rcParams['lines.color'] = 'r'
# 修改方式二
matplotlib.rc('lines', linewidth=4, color='g')
# 恢复默认参数
matplotlib.rcdefaults()
In [ ]:
# 显示所有默认配置
print(matplotlib.rc_params())
In [ ]:
print(plt.style.available)
plt.style.use('ggplot')
In [ ]:
# 中文 (不起作用, /usr/local/lib/python3.6/dist-packages/matplotlib/mpl-data/matplotlibrc)
# https://yun.baidu.com/disk/home?#/all?vmode=list&path=%2F%E6%88%91%E7%9A%84%E8%B5%84%E6%BA%90%2F%E5%AD%97%E4%BD%93
plt.rcParams['font.sans-serif'] = 'SimHei'
# 负号正常显示
plt.rcParams['axes.unicode_minus'] = False
# 图像显示大小
plt.rcParams['figure.figsize'] = (6.0, 6.0)
# 使用数学公式 (depend: sudo apt install texlive-full)
plt.rcParams['text.usetex'] = True
plt.rcParams['text.latex.preamble'] = [r'\usepackage{amsmath}']
# 更多preamble, \newcommand自定义命令
plt.rcParams['text.latex.preamble'] = [
r'\usepackage{amsmath}',
r'\usepackage{helvet}',
r'\usepackage{sansmath}',
r'\sansmath',
r'\renewcommand{\familydefault}{\sfdefault}',
r'\usepackage[T1]{fontenc}',
r'\usepackage{graphicx}',
r'\usepackage{relsize}',
r'\newcommand{\bigpi}{\scalebox{5}{\ensuremath{\pi}}}'
]
# 坐标label字体大小
plt.rcParams['axes.labelsize'] = 16
# 图像 插补方式: 紧邻
plt.rcParams['image.interpolation'] = 'nearest'
# color map
plt.rcParams['image.cmap'] = 'gray'
In [ ]:
# 保存图像像素
plt.rcParams['savefig.dpi'] = 300
# 图像分辨率
plt.rcParams['figure.dpi'] = 300
# 设置线条样式
plt.rcParams['lines.linestyle'] = '-.'
# 设置线条宽度
plt.rcParams['lines.linewidth'] = 3
# 设置线条标识
plt.rcParams['lines.marker'] = 'o'
In [ ]:
# 不显示坐标轴
plt.axis('off')