Abstract
I am trying to find a way to make the nodes transparent. In the simple case, the transparency of a node is simply specified by the "alpha" option of "nx.draw". However, I thought I could specify the transparency with a list, just as I specified the color with a list, but failed. Do you know the reason for this?
import networkx as nx
G = nx.Graph()
G.add_node('A')
G.add_node('B')
G.add_node('C')
G.add_node('D')
G.add_node('E')
G.add_edge('A', 'B')
G.add_edge('A', 'C')
G.add_edge('A', 'D')
G.add_edge('B', 'D')
G.add_edge('D', 'E')
node_alpha = [1, 0.8, 0.6, 0.4, 0.2]
nx.draw(G, alpha=node_alpha, with_labels = True)
plt.figure()
The following error occurred
Traceback (most recent call last):
File "C:/Program Files/Python36/transparency.py", line 19, in <module>
nx.draw(G, alpha=node_alpha, with_labels = True)
File "C:\Users\████\AppData\Roaming\Python\Python36\site-packages\networkx\drawing\nx_pylab.py", line 123, in draw
draw_networkx(G, pos=pos, ax=ax, **kwds)
File "C:\Users\████\AppData\Roaming\Python\Python36\site-packages\networkx\drawing\nx_pylab.py", line 336, in draw_networkx
draw_networkx_edges(G, pos, arrows=arrows, **edge_kwds)
File "C:\Users\████\AppData\Roaming\Python\Python36\site-packages\networkx\drawing\nx_pylab.py", line 684, in draw_networkx_edges
alpha=alpha,
File "C:\Users\████\AppData\Roaming\Python\Python36\site-packages\matplotlib\collections.py", line 1391, in __init__
**kwargs)
File "C:\Users\████\AppData\Roaming\Python\Python36\site-packages\matplotlib\cbook\deprecation.py", line 411, in wrapper
return func(*inner_args, **inner_kwargs)
File "C:\Users\████\AppData\Roaming\Python\Python36\site-packages\matplotlib\collections.py", line 213, in __init__
self.update(kwargs)
File "C:\Users\████\AppData\Roaming\Python\Python36\site-packages\matplotlib\artist.py", line 998, in update
ret.append(func(v))
File "C:\Users\████\AppData\Roaming\Python\Python36\site-packages\matplotlib\collections.py", line 834, in set_alpha
super().set_alpha(alpha)
File "C:\Users\████\AppData\Roaming\Python\Python36\site-packages\matplotlib\artist.py", line 930, in set_alpha
raise TypeError('alpha must be a float or None')
TypeError: alpha must be a float or None
We believe that the image will be as follows