【发布时间】:2015-07-29 06:56:56
【问题描述】:
我想在 Python 中更改默认绘图的外观,因此我在当前工作目录 (Windows 7) 中创建了文件 matplotlibrc。文件被加载 -
import matplotlib as mp
print('Config. file loaded from:', mp.matplotlib_fname())
返回
Config. file loaded from: C:\Users\mato\Documents\Python_Scripts\matplotlibrc
不过剧情不受影响。
简单代码:
import matplotlib.pyplot as plt
x = [1,2,3,4,5]
plt.plot(x)
matplotlibrc 文件看起来像这样:
lines.linestyle : --
axes.grid : True
生成带有实线且图中没有网格的图。我错过了什么?
【问题讨论】:
-
您是否从matplotlib.org/users/customizing.html(或您的系统文件夹)编辑了matplotlibrc 模板?看起来这总是从使用
backend : [DEFAULT]行指定默认后端开始。可能是它忽略您的本地文件的原因... -
我从编辑模板文件开始,但为了简单起见,切换到上面显示的 2 行。当前工作目录是 python 查找 matplotlibrc 的第一个位置。
-
没有在
matplotlibrc中指定后端我根本没有得到一个情节(在Linux上)。使用您的matplotlibrc文件,变量mp.rcParams['lines.linestyle']和mp.rcParams['axes.grid']已正确指定,并且按预期工作...如果您在代码中设置值(例如mp.rcParams['lines.linestyle']='--'),这是否会按预期更改线条样式?可能是后端绘图有问题,或者选项可能以某种方式被覆盖。 -
如果我在代码中插入 plt.rcParams['axes.grid']=True plt.rcParams['lines.linestyle']='--'按预期工作
标签: python matplotlib plot configuration configuration-files