5

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()
sentence
  • 8,213
  • 4
  • 31
  • 40
Priyank Vashiar
  • 181
  • 3
  • 12
  • 1
    I found an answer. 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)` – Priyank Vashiar Aug 09 '19 at 20:30
  • 4
    Please post your solution as answer and accept it. Then everybody can profit from it. (See guideline: https://stackoverflow.com/help/self-answer) – Sparky05 Aug 09 '19 at 20:39

1 Answers1

5

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)

Priyank Vashiar
  • 181
  • 3
  • 12