문제 설명
networkx .module 'matplotlib.pyplot'에서 그래프를 그리는 동안 오류가 발생했습니다. (Error while drawing a graph in networkx .module 'matplotlib.pyplot' has no attribute 'ishold')
networkx를 사용하여 그래프를 플로팅하고 싶습니다. 그러나 'matplotlib.pyplot' 모듈에는 'ihold' 속성이 없습니다. 오류가 발생합니다. 이전 버전의 matplotlib를 사용해 보았지만 작동하지 않았습니다. 어제 동일한 코드가 실행되었지만 지금은 이 오류가 표시됩니다. 도와주세요. 막혔습니다.
이전 버전의 matplotlib를 사용해 보았지만 작동하지 않았습니다. 어제 동일한 코드가 실행되었지만 지금은 이 오류가 표시됩니다. 도와주세요. 막혔습니다.
import networkx as nx
import numpy as np
import matplotlib.pyplot as plt
G = nx.Graph()
G.add_edges_from(
[('A', 'B'), ('A', 'C'), ('D', 'B'), ('E', 'C'), ('E', 'F'),
('B', 'H'), ('B', 'G'), ('B', 'F'), ('C', 'G')])
val_map = {'A': 1.0,
'D': 0.5714285714285714,
'H': 0.0}
values = [val_map.get(node, 0.25) for node in G.nodes()]
%matplotlib inline
nx.draw_networkx(G, cmap = plt.get_cmap('jet'), node_color = values)
nx.draw(G)
plt.show()
AttributeError Traceback (most recent call last)
<ipython‑input‑13‑127734f4f34b> in <module>()
14 values = [val_map.get(node, 0.25) for node in G.nodes()]
15 get_ipython().magic('matplotlib inline')
‑‑‑> 16 nx.draw_networkx(G, cmap = plt.get_cmap('jet'), node_color = values)
17
18 nx.draw(G)
1 frames
/usr/local/lib/python3.6/dist‑packages/networkx/drawing/nx_pylab.py in draw_networkx_edges(G, pos, edgelist, width, edge_color, style, alpha, edge_cmap, edge_vmin, edge_vmax, ax, arrows, label, **kwds)
520 lw = width
521
‑‑> 522 if not cb.is_string_like(edge_color) \
523 and cb.iterable(edge_color) \
524 and len(edge_color) == len(edge_pos):
AttributeError: module 'matplotlib.cbook' has no attribute 'is_string_like'
참조 솔루션
방법 1:
I had the same issue, it's due to a mismatch in the versions of networkx and matplotlib. I tried uninstalling and reinstalling the packages ‑ it worked!
sudo pip3 uninstall networkx
sudo pip3 uninstall matplotlib
python3 ‑mpip uninstall matplotlib
sudo conda uninstall matplotlib
If you've installed networkx via other sources like mpip or conda, uninstall via those too.
Then install both of them:
sudo pip3 install networkx
sudo pip3 install matplotlib
방법 2:
I downgraded matplotlib version to 2.2.3 and it works.
just input
pip install matplotlib==2.2.3.
hope it helps~
(by anonymous、Bharg、Tianmin Lyu)