Python/matplotlib:如何消除matplotlib.mpl警告

16

我正在使用Python 3.4的Matplotlib库。 当我启动程序时,出现以下警告信息:

C:\Python34-32bits\lib\site-packages\matplotlib\cbook.py:123: MatplotlibDeprecationWarning:在版本1.3中,matplotlib.mpl模块已过时。请改用import matplotlib as mpl。 warnings.warn(message, mplDeprecation, stacklevel=1)

据我所知,我没有使用mpl,并且所有关于Matplotlib的导入都为:

import matplotlib.pyplot as plt
import matplotlib.animation as animation

有什么我应该做的吗?


你在使用哪个版本的matplotlib? - MrAlias
5个回答

41

您可以抑制特定的警告,这可能是首选的方法:

import warnings
import matplotlib.cbook
warnings.filterwarnings("ignore",category=matplotlib.cbook.mplDeprecation)

3

当导入模块时,您可以临时禁止警告

import warnings

def fxn():
    warnings.warn("deprecated", DeprecationWarning)

with warnings.catch_warnings():
    warnings.simplefilter("ignore")
    fxn()

2
我可以用以下代码来抑制该警告:
import warnings

warnings.filterwarnings("ignore",category=UserWarning)

0

看到代码会很有用,但请记住先设置绘图参数,然后再初始化绘图

例如,你可能已经做过的事情:

plt.pcolormesh(X, Y, Z)
plt.axes().set_aspect('equal')

你需要做什么:

plt.axes().set_aspect('equal')
plt.pcolormesh(X, Y, Z)

0

由于

MatplotlibDeprecationWarning: mplDeprecation 在 Matplotlib 3.6 中已被弃用,并将在两个次要版本后被删除...

请改用以下内容:

import warnings
import matplotlib
warnings.filterwarnings("ignore", category=matplotlib.MatplotlibDeprecationWarning)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接