TimeoutError: Lock error: Matplotlib failed to acquire the following lock file

TimeoutError: Lock error: Matplotlib failed to acquire the following lock file

我得到错误:

TimeoutError: Lock error: Matplotlib failed to acquire the following lock file

当我删除设置字体命令前的注释# 时。为什么?请问如何更正?

import matplotlib.pyplot as plt

params = {'text.usetex' : True,
          'font.size' : 8,
          'font.family' : 'lmodern'
          }
#plt.rcParams.update(params)

fig, ((ax01, ax02, ax03, ax0), (ax1, ax2, ax3, ax4), (ax5, ax6, ax7, ax8), (ax9, ax10, ax11, ax12)) = plt.subplots(nrows=4, ncols=4, figsize=(12,7))



for ax in [ax1, ax2, ax3, ax4, ax5, ax6, ax7, ax8, ax9, ax10, ax11, ax12]: 
    ax.set_xlim(0,1000) 
    ax.ticklabel_format(useOffset=False)

plt.tight_layout()
plt.show()

将我的评论放入答案中:您似乎需要删除 matplotlib 缓存文件夹。可以在 Python 内完成:

import pathlib
import matplotlib as mpl

pathlib.Path.rmdir( mpl.get_cachedir())

另外,您可以整理轴定义和迭代:

fig, axes = plt.subplots(nrows=4, ncols=4, figsize=(12,7))


for ax in axes.ravel(): 
    ax.set_xlim(0,1000) 
    ax.ticklabel_format(useOffset=False)