从显示中删除matplotlib折旧警告

从显示中删除matplotlib折旧警告

本文介绍了从显示中删除matplotlib折旧警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是得到了一个MatplotlibDepreciationWarning,我不想在控制台上看到它.因此,我不想看到它.

I'm getting simply a MatplotlibDepreciationWarning which I don't like to see on my console. And therefore I don't want to see it.

这是警告:

/home/.../pyvirt/networkx/lib/python3.6/site-packages/networkx/drawing/nx_pylab.py:579:
MatplotlibDeprecationWarning:The iterable function was deprecated in Matplotlib 3.1 and will be removed in 3.3. Use np.iterable instead.
        if not cb.iterable(width):`

因此,如果有人可以提出任何建议以消除此折旧警告的显示,我们将不胜感激.

So if anyone can suggest any way to remove this depreciation warning from showing, it would be appreciated.

我尝试过:

import warnings
warnings.filterwarnings("ignore", category=DepriciationWarning)`

程序代码如下,其中不包含任何错误.

Code for program is as follow which doesn't contain any error.

import networkx as nx
import matplotlib.pyplot as plt
import random

G=nx.Graph()
city_set=['Delhi','Bangalore','Hyderabad','Ahmedabad','Chennai','Kolkata','Surat','Pune','Jaipur']
for each in city_set:
    G.add_node(each)

costs=[]
value=100
while(value<=2000):
    costs.append(value)
    value=value+100

while(G.number_of_edges()<16):
    c1=random.choice(list(G.nodes()))
    c2=random.choice(list(G.nodes()))
    if c1!=c2 and G.has_edge(c1,c2)==0:
        w=random.choice(costs)
        G.add_edge(c1,c2,weight=w)

for u in G.nodes():
    for v in G.nodes():
        print(u,v,nx.has_path(G,u,v))

pos=nx.circular_layout(G)
nx.draw(G,pos,with_labels=1)
plt.show()

推荐答案

对于matplotlib,类别应该是 UserWarning ,而不是category = DepreciationWarning.因此,解决方案是在代码开始前添加以下行-

Instead of category=DepreciationWarning, category was supposed to be UserWarning for matplotlib. Therefore solution is add the following lines before starting of code-

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

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

这篇关于从显示中删除matplotlib折旧警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-04 21:42