我有以下非常简单的代码:
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'
发生了什么事,我该如何解决?