0

When drawing graphs in Networkx, I am wondering if there is a way to specify alpha for each edge and node - similar to how the node_color or edge_color can be a list of colors. The goal is to be able to selectively highlight a subgraph of a larger graph.

1 Answers1

4

If you use draw_networkx_nodes, you can pass in an array of floats to the alpha argument like you would do for node_color.

Edit based on comment from @AveragePythonEnjoyer

draw_networkx_edges does offer the same functionality, so you can pass a list of floats to the alpha argument the same length as the number of edges for that one as well!

If the lists that you pass into the alpha argument are shorter than the number of nodes/edges, the values will cycle through the list then restart at the beginning until the number of nodes/edges is covered. If the list is longer than the number of nodes/edges, only the number of values corresponding to the number of nodes/edges will be used.

Both draw_networkx_nodes and draw_networkx_edges require you to pass in a pos argument for node positions, so those must be defined in advance.

Andrew
  • 789
  • 1
  • 6
  • 3
    It does offer the same functionality. – AveragePythonEnjoyer Oct 18 '22 at 12:36
  • 1
    Good to know, thank you! Updated answer with that information. Should have tested it myself before posting instead of just trusting the documentation! – Andrew Oct 18 '22 at 21:07
  • Exactly what I was looking for. For reference, if anyone else also needed to extract `pos` in order to get this working, [this post](https://stackoverflow.com/a/11809184/14651805) helped me as well. – Elijah Pelofske Oct 18 '22 at 22:11