用matplotlib.pyplot绘图时遇到的一些问题

今天在使用matplotlib.pyplot绘图时遇到一些问题,原代码如下:

from sympy import *
from sympy.plotting import plot3d
from sympy.abc import x, y
from 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$')

运行此代码,程序报错如下:

Exception in Tkinter callback
Traceback (most recent call last):
...
TimeoutError: Lock error: Matplotlib failed to acquire the following lock file:
    C:\Users\admin\.matplotlib\tex.cache\e79e5a4b590babc4e59f5cc7000ce83a.tex.matplotlib-lock
This maybe due to another process holding this lock file.  If you are sure no
other Matplotlib process is running, remove this file and try again.
Exception in Tkinter callback
Traceback (most recent call last):
...
TimeoutError: Lock error: Matplotlib failed to acquire the following lock file:
    C:\Users\admin\.matplotlib\tex.cache\e79e5a4b590babc4e59f5cc7000ce83a.tex.matplotlib-lock
This maybe due to another process holding this lock file.  If you are sure no
other 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 plot3d
from sympy.abc import x, y
from 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$')

程序可以正常运行,结果如下。用LaTeX字体

如果将上面那一行注释:

from sympy import *
from sympy.plotting import plot3d
from sympy.abc import x, y
from 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$')

程序依然可以运行。更改字号
不知道是否有方法可以让两行代码同时起作用。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值