Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove matplotlib depreciation warning from showing

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.

Here's the warning:

/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.

I've tried:

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()
like image 480
Priyank Vashiar Avatar asked Aug 09 '19 20:08

Priyank Vashiar


People also ask

What is deprecation warning in Python?

It is a subclass of Exception . UserWarning. The default category for warn() . DeprecationWarning. Base category for warnings about deprecated features when those warnings are intended for other Python developers (ignored by default, unless triggered by code in __main__ ).


1 Answers

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)

like image 117
Priyank Vashiar Avatar answered Sep 29 '22 17:09

Priyank Vashiar