Python/matplotlib:摆脱matplotlib.mpl警告

2024-05-06 18:12:02 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用matplotlib和python 3.4。 当我启动程序时,会显示以下警告消息:

C:\Python34-32bits\lib\site-packages\matplotlib\cbook.py:123: MatplotlibDeprecationWarning: The matplotlib.mpl module was deprecated in version 1.3. Use import matplotlib as mpl instead. warnings.warn(message, mplDeprecation, stacklevel=1)

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

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

我该怎么办?


Tags: pyimport程序消息警告matplotliblibpackages
3条回答

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

例如,你可能做了什么:

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

你要做的是:

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

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

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

导入时可以temporarily suppress a warning

import warnings

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

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

相关问题 更多 >