今天在使用matplotlib.pyplot绘图时遇到一些问题,原代码如下:
from sympy import *from sympy.plotting import plot3dfrom sympy.abc import x, yfrom pylab import rcrc(\'text\', usetex=True); rc(\'font\', size=16)plot3d(sin(sqrt(x**2+y**2)), (x, -10, 10), (y, -10, 10), xlabel=r\'$x$\', ylabel=r\'$y$\')
运行此代码,程序报错如下:
Exception in Tkinter callbackTraceback (most recent call last):...TimeoutError: Lock error: Matplotlib failed to acquire the following lock file:C:\\Users\\admin\\.matplotlib\\tex.cache\\e79e5a4b590babc4e59f5cc7000ce83a.tex.matplotlib-lockThis maybe due to another process holding this lock file. If you are sure noother Matplotlib process is running, remove this file and try again.Exception in Tkinter callbackTraceback (most recent call last):...TimeoutError: Lock error: Matplotlib failed to acquire the following lock file:C:\\Users\\admin\\.matplotlib\\tex.cache\\e79e5a4b590babc4e59f5cc7000ce83a.tex.matplotlib-lockThis maybe due to another process holding this lock file. If you are sure noother Matplotlib process is running, remove this file and try again.
按照网上的查询结果删除了
\"venv\\lib\\site-packages\\matplotlib\\cbook\\__init__.py\"
,程序依然报错,此时的错误信息是
AttributeError: module \'matplotlib.cbook\' has no attribute \'deprecated\'
。
加回那个文件,此时将代码进行如下注释:
from sympy import *from sympy.plotting import plot3dfrom sympy.abc import x, yfrom pylab import rcrc(\'text\', usetex=True)#rc(\'font\', size=16)plot3d(sin(sqrt(x**2+y**2)), (x, -10, 10), (y, -10, 10), xlabel=r\'$x$\', ylabel=r\'$y$\')
程序可以正常运行,结果如下。
如果将上面那一行注释:
from sympy import *from sympy.plotting import plot3dfrom sympy.abc import x, yfrom pylab import rc#rc(\'text\', usetex=True)rc(\'font\', size=16)plot3d(sin(sqrt(x**2+y**2)), (x, -10, 10), (y, -10, 10), xlabel=r\'$x$\', ylabel=r\'$y$\')
程序依然可以运行。
不知道是否有方法可以让两行代码同时起作用。