0

is it possible / is there a better way of adding 2 parallel edges between 2 nodes in networkx? ideally these edges may be different sizes / colours.
below is how I want the output to look, which I have pieced together by adding several nodes which end up hidden - but kept the edges visible, and just overlaid 2 nodes over the top (which have no edge connections).
ideally I would just like to have 2 nodes and have the ability to connect them with multiple edges, but can't seem to work it out.

Thanks,

from matplotlib import pyplot as plt
import networkx as nx

fig, ax = plt.subplots(figsize=(10, 5))

graph = nx.MultiGraph()

graph.add_node(1, pos=(0.2, 0.5))
graph.add_node(2, pos=(0.8, 0.5))

# these nodes will be invisible
graph.add_node(3, pos=(0.8, 0.51))
graph.add_node(4, pos=(0.2, 0.51))
graph.add_node(5, pos=(0.8, 0.49))
graph.add_node(6, pos=(0.2, 0.49))

graph.add_edge(3,4)
graph.add_edge(5,6)

pos = nx.get_node_attributes(graph,'pos')

nx.draw(graph, pos, edge_color=['r','g'], width=[7.0,5.0], node_color=[(0.0,0.0,0.0,1.0),(0.0,0.0,0.0,1.0),(0.0,0.0,0.0,0.0),(0.0,0.0,0.0,0.0),(0.0,0.0,0.0,0.0),(0.0,0.0,0.0,0.0)])

# axis
ax.set_axis_on()
ax.tick_params(left=True, bottom=True, labelleft=True, labelbottom=True)

# limit
plt.xlim([0.0, 1.0])
plt.ylim([0.0, 1.0])

plt.show()

enter image description here

ChrisM
  • 309
  • 5
  • 19
  • Unfortunately, networkx doesn't have good native support for visualizing multiple parallel edges (see [1](https://stackoverflow.com/questions/56543559/networkx-drawing-parallel-edges) and [2](https://stackoverflow.com/questions/22785849/drawing-multiple-edges-between-two-nodes-with-networkx), for example). Those linked threads provide several options for workarounds / other packages to consider, but you're likely going to move away from using `nx.draw()`. Instead, separate the plotting compands into `nx.draw_networkx_nodes()` followed by multiple calls of `nx.draw_networkx_edges()`. – Frodnar Nov 10 '21 at 20:27

0 Answers0