matplotlip参数配置

 

代码中配置matplotlib参数

 

# 以下mpl均可以用plt进行替代:import matplotlib.pyplot as plt
import matplotlib as mpl
mpl.rcParams['lines.linewidth'] = 2
mpl.rcParams['axes.prop_cycle'] = mpl.cycler(color='r')

#or
mpl.rc('lines', linewidth = 2)
mpl.rc('axes',prop_cycle = mpl.cycler(color='r'))

#重置配置
mpl.rcdefaults()

 

使用配置文件进行matplotlib配置

 1.当前目录

  在当前目录中保存文件名为matplotlibrc的文件,用于当前目录中代码的matplotlib配置

 

2.用户级配置文件

  保存在用户根目录中~/.matplotlib/matplotlibrc,用于用户级别的matplotlib配置。

#Shell中打印配置文件目录的方法:
$ python -c 'import matplotlib as mpl; print(mpl.get_configdir())'
# Python代码中取得配置文件目录
import matplotlib as mpl

mpl.get_configdir()

 

3.安装级配置文件

  保存在matplotlib模块安装目录

#通过Python代码取得matplotlib系统级配置文件

import os
import matplotlib as mpl

mpl_module_dir = os.path.dirname(mpl.__file__)
mpl_rc_dir = os.path.join(mpl_module_dir,'mpl-data')

 

posted @ 2020-12-09 11:26  不懂技术  阅读(169)  评论(0编辑  收藏  举报