networkx .module 'matplotlib.pyplot'에서 그래프를 그리는 동안 오류가 발생했습니다. (Error while drawing a graph in networkx .module 'matplotlib.pyplot' has no attribute 'ishold')


문제 설명

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 anonymousBhargTianmin Lyu)

참조 문서

  1. Error while drawing a graph in networkx .module 'matplotlib.pyplot' has no attribute 'ishold' (CC BY‑SA 2.5/3.0/4.0)

#networkx #matplotlib






관련 질문

단순 팻테일 로그 비닝 (Simple fat-tailed log-binning)

NetworkX - 노드 묶기 중지 - 시도된 Scale/K 매개변수 (NetworkX - Stop Nodes from Bunching Up - Tried Scale/K parameters)

문자열의 int 부분으로 문자열 레이블의 노드에 액세스 (Access a node of string label with an int part of the string)

시계열 분석을 위해 Pandas Groupby 및 date_range를 사용하는 동안 오류가 발생했습니다. (Error using Pandas Groupby and date_range for timeseries analysis)

regraph 계층 구조에서 가장자리 속성을 자리 표시자로 사용하는 방법이 있습니까? (Is there a way to have edge attributes as placeholders in a regraph hierarchy?)

networkx .module 'matplotlib.pyplot'에서 그래프를 그리는 동안 오류가 발생했습니다. (Error while drawing a graph in networkx .module 'matplotlib.pyplot' has no attribute 'ishold')

svg의 NetworkX node_shape (NetworkX node_shape from svg)

그래프를 통해 그래프 노드인 클래스 인스턴스의 속성에 액세스하는 방법은 무엇입니까? (How to access attributes of a class instance which is a graph node via the graph?)

그래프의 이미지를 분리하는 방법은 무엇입니까? (How to separate images of graphs?)

networkx 도면을 업데이트하는 방법 (How to update a networkx drawing)

그래프 노드 간의 메시지 흐름을 위한 Python 함수 (Python function for message flow between nodes of a graph)

networkx에서 임의의 에지 가중치를 사용하여 여러 임의의 그래프를 효율적으로 생성하는 방법 (How to efficiently generate multiple random graphs with random edge weights in networkx)







코멘트