从显示中删除matplotlib折旧警告

时间:2019-08-09 20:25:57

标签: python python-3.x matplotlib networkx

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

这是警告:

/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):`

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

我尝试过:

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

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

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()

1 个答案:

答案 0 :(得分:2)

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

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