'Error in getting network figure in python networkx
I'm running this code to get a network figure. I'm using networkx package in python.
from pylab import rcParams
rcParams['figure.figsize'] = 14, 10
pos = nx.spring_layout(g, scale=20, k=3/np.sqrt(g.order()))
d = dict(g.degree)
plt.figure(figsize=(10, 9))
nx.draw(g, pos, node_color='green',
with_labels=True,
nodelist=d,
node_size=[d[k]*200 for k in d])
But getting the following error. This code runs fine in Kaggle or Colab but problem occurs when I try to run this segment in jupyter Notebook of my computer.
IndexError Traceback (most recent call last)
~\anaconda3\lib\site-packages\networkx\utils\decorators.py in _random_state(func, *args, **kwargs)
395 try:
--> 396 random_state_arg = args[random_state_index]
397 except TypeError as e:
IndexError: tuple index out of range
The above exception was the direct cause of the following exception:
NetworkXError Traceback (most recent call last)
<ipython-input-18-83602777a5ba> in <module>
1 from pylab import rcParams
2 rcParams['figure.figsize'] = 14, 10
----> 3 pos = nx.spring_layout(g, scale=20, k=3/np.sqrt(g.order()))
4 d = dict(g.degree)
5 plt.figure(figsize=(10, 9))
~\anaconda3\lib\site-packages\decorator.py in fun(*args, **kw)
229 if not kwsyntax:
230 args, kw = fix(args, kw, sig)
--> 231 return caller(func, *(extras + args), **kw)
232 fun.__name__ = func.__name__
233 fun.__doc__ = func.__doc__
~\anaconda3\lib\site-packages\networkx\utils\decorators.py in _random_state(func, *args, **kwargs)
398 raise nx.NetworkXError("random_state_index must be an integer") from e
399 except IndexError as e:
--> 400 raise nx.NetworkXError("random_state_index is incorrect") from e
401
402 # Create a numpy.random.RandomState instance
NetworkXError: random_state_index is incorrect
Any solution anyone?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
