Python/matplotlib : getting rid of matplotlib.mpl warning

*爱你&永不变心* 提交于 2020-01-10 18:21:05

问题


I am using matplotlib using python 3.4. When I start my program, I have the following warning message:

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)

As far as I know I do not use mpl, and all my imports concerning matplotlib are:

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

Anything I should do ?


回答1:


You can suppress that particular warning, which is probably the preferred way:

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



回答2:


you can temporarily suppress a warning, when importing

import warnings

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

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



回答3:


It would be useful to see the code, however remember to set the parameters of the plot first, only then initialize the plot.

Exemple, what you may have done:

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

What you have to do:

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


来源:https://stackoverflow.com/questions/24502500/python-matplotlib-getting-rid-of-matplotlib-mpl-warning

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!