matplotlib错误:UserWarning:找不到rc文件

加百列

我有以下非常简单的代码:

import matplotlib.pyplot as plt 
import numpy as np
import matplotlib.gridspec as gridspec

x = np.random.randn(60) 
y = np.random.randn(60)
z = [np.random.random() for _ in range(60)]

fig = plt.figure()
gs = gridspec.GridSpec(1, 2)

ax0 = plt.subplot(gs[0, 0])
plt.scatter(x, y, s=20)

ax1 = plt.subplot(gs[0, 1])
cm = plt.cm.get_cmap('RdYlBu_r')
plt.scatter(x, y, s=20 ,c=z, cmap=cm, vmin=0, vmax=1)
cbaxes = fig.add_axes([0.6, 0.12, 0.1, 0.02]) 
plt.colorbar(cax=cbaxes, ticks=[0.,1], orientation='horizontal')

fig.tight_layout()

out_png = '/home/user/image_out.png'
plt.savefig(out_png, dpi=150)
plt.close()

如果我在机器上运行它,则除警告以外,它都可以工作:

/usr/local/lib/python2.7/dist-packages/matplotlib/figure.py:1533: UserWarning: This figure includes Axes that are not compatible with tight_layout, so its results might be incorrect.
  warnings.warn("This figure includes Axes that are not "

但是,如果我在群集上运行它,则会退出并显示以下错误:

/usr/lib/pymodules/python2.7/matplotlib/__init__.py:611: UserWarning: Could not find matplotlibrc; using defaults
  warnings.warn('Could not find matplotlibrc; using defaults')
/usr/lib/pymodules/python2.7/matplotlib/__init__.py:698: UserWarning: could not find rc file; returning defaults
  warnings.warn(message)
Traceback (most recent call last):
  File "colorbar.py", line 7, in <module>
    import matplotlib.pyplot as plt 
  File "/usr/lib/pymodules/python2.7/matplotlib/pyplot.py", line 23, in <module>
    from matplotlib.figure import Figure, figaspect
  File "/usr/lib/pymodules/python2.7/matplotlib/figure.py", line 18, in <module>
    from axes import Axes, SubplotBase, subplot_class_factory
  File "/usr/lib/pymodules/python2.7/matplotlib/axes.py", line 14, in <module>
    import matplotlib.axis as maxis
  File "/usr/lib/pymodules/python2.7/matplotlib/axis.py", line 10, in <module>
    import matplotlib.font_manager as font_manager
  File "/usr/lib/pymodules/python2.7/matplotlib/font_manager.py", line 1325, in <module>
    _rebuild()
  File "/usr/lib/pymodules/python2.7/matplotlib/font_manager.py", line 1275, in _rebuild
    fontManager = FontManager()
  File "/usr/lib/pymodules/python2.7/matplotlib/font_manager.py", line 962, in __init__
    paths = [os.path.join(rcParams['datapath'], 'fonts', 'ttf'),
  File "/usr/lib/python2.7/posixpath.py", line 77, in join
    elif path == '' or path.endswith('/'):
AttributeError: 'NoneType' object has no attribute 'endswith'

发生了什么事,我该如何解决?

弗朗切斯科·蒙特萨诺(Francesco Montesano)
  1. 第一个警告与方法有关,axes并被subplots创建。axes是在指定尺寸的同时创建的,同时subplots将轴放置在常规网格中。

    因此tight_layout,无法调整大小axessubplots您会得到警告。因此,使用axessubplotstight_layout可能需要大量的调整中fig.add_axes([0.6, 0.12, 0.1, 0.02])

  2. 在我看来,在群集上运行时遇到的错误与matplotlib安装中的某些问题有关。该警告的含义是:matplotlibmatplotlibrc在任何标准位置均未找到任何文件,因此它将使用默认(硬编码)参数。然后,它期望找到一个参数'datapath'但是不存在(或错误定义为None),因此rcParams['datapath']返回None

    然后,将参数传递给os.path.joinwich期望的字符串,而不是NoneType

    您可以查看是否正在获取matplotlibrc文件并将其放置在当前目录中,或者~/.config/matplotlib可以解决您的问题。

    您应该做的另一件事是检查matplotlib的版本,以及您运行的版本是否是您认为正在运行的版本。

    python -c 'import matplotlib; print(matplotlib.__version__); print(matplotlib.__file__)'
    

ps:我gs = gridspec.GridSpec(1, 2)根本不认为您需要,除非您随后对轴做一些额外的操作。如果您这样做,则会得到完全相同的答案

fig = plt.figure(...)
ax0 = fig.add_subplot(121)
ax1 = fig.add_subplot(122)

或者

fig, (ax0, ax1) = plt.subplots(nrows=1, ncols=2, ...)

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

DLL的NET Core加载接口获取错误找不到文件(VS2017 RC)

来自分类Dev

错误53找不到文件

来自分类Dev

错误53找不到文件

来自分类Dev

找不到StorageFolder文件错误

来自分类Dev

mysqlimport找不到文件错误

来自分类Dev

错误53找不到文件

来自分类Dev

mongodb错误找不到文件

来自分类Dev

GAE:找不到文件错误

来自分类Dev

找不到 Git 错误/文件

来自分类Dev

iframe“找不到文件”错误

来自分类Dev

matplotlib找不到配置文件matplotlibrc

来自分类Dev

找不到matplotlib数据文件

来自分类Dev

找不到文件错误,但文件存在

来自分类Dev

`错误!找不到dkms.conf文件`

来自分类Dev

使用rgmagick并获得找不到文件的错误

来自分类Dev

找不到文件错误Google Drive API

来自分类Dev

runspider:错误:找不到文件:-Scrapy

来自分类Dev

Gradle错误:找不到属性文件

来自分类Dev

Javah错误,找不到类文件

来自分类Dev

Impala-找不到文件错误

来自分类Dev

Cordova-Android-找不到文件错误

来自分类Dev

找不到NSManagedObject.h文件错误

来自分类Dev

找不到'stdarg.h'文件错误

来自分类Dev

耙错误找不到耙文件

来自分类Dev

错误“找不到文件”保存ActiveWorkbook

来自分类Dev

Google Colab Notebook错误-找不到文件

来自分类Dev

Python导入错误,找不到某些文件

来自分类Dev

致命错误:找不到“特征/密集”文件

来自分类Dev

使用rgmagick并获得找不到文件的错误