Pri*_*iar 5 python matplotlib networkx python-3.x
我只是收到一个 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):`
Run Code Online (Sandbox Code Playgroud)
因此,如果有人可以建议任何方法来消除显示的折旧警告,我们将不胜感激。
我试过了:
import warnings
warnings.filterwarnings("ignore", category=DepriciationWarning)`
Run Code Online (Sandbox Code Playgroud)
程序代码如下,不包含任何错误。
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()
Run Code Online (Sandbox Code Playgroud)
matplotlib的类别应该是UserWarning ,而不是category=DepreciationWarning。因此,解决方案是在代码开始之前添加以下行 -
import warnings
warnings.filterwarnings("ignore", category=UserWarning)
| 归档时间: |
|
| 查看次数: |
7468 次 |
| 最近记录: |