16

我正在使用 python 3.4 使用 matplotlib。当我启动我的程序时,我收到以下警告消息:

C:\Python34-32bits\lib\site-packages\matplotlib\cbook.py:123: MatplotlibDeprecationWarning: matplotlib.mpl 模块在 1.3 版中已弃用。改为使用import matplotlib as mpl。warnings.warn(消息,mplDeprecation,stacklevel=1)

据我所知,我不使用 mpl,我所有关于 matplotlib 的导入都是:

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

有什么我应该做的吗?

4

4 回答 4

38

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

import warnings
import matplotlib.cbook
warnings.filterwarnings("ignore",category=matplotlib.cbook.mplDeprecation)
于 2014-07-01T05:13:51.883 回答
3

您可以在导入时暂时抑制警告

import warnings

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

with warnings.catch_warnings():
    warnings.simplefilter("ignore")
    fxn()
于 2014-07-01T05:09:49.203 回答
1

我能够使用以下代码抑制该警告:

import warnings

warnings.filterwarnings("ignore",category=UserWarning)
于 2020-03-30T00:39:59.920 回答
0

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

例如,你可能做了什么:

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

你必须做的:

plt.axes().set_aspect('equal')
plt.pcolormesh(X, Y, Z)
于 2018-06-30T14:30:50.443 回答