【问题标题】:matplotlibrc has no effect on the plot?matplotlibrc 对情节没有影响?
【发布时间】: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


【解决方案1】:

我遇到了同样的问题,解决方法是简单地取消注释命令。(删除您要更改的参数之前的“#”) 天哪!

【讨论】:

  • 请详细说明并具体说明代码更改。
猜你喜欢
  • 2019-05-02
  • 2020-11-10
  • 2015-11-04
  • 2010-12-01
  • 2013-10-07
  • 2021-12-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多