-
Notifications
You must be signed in to change notification settings - Fork 193
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Information
- rustworkx version: 0.12.1
- Python version: 3.9
- Rust version: I do not know, but not relevant for this issue.
- Operating system: macOs
What is the current behavior?
When plotting a multigraph with parallel edges using rustworkx.visualization.mpl_draw()
, two issues occur:
- The arrows for multiple edges are printed on top of each other.
- Only one label is drawn for every pair of nodes. (The labels are currently saved in a dict, which uses node pair as the key.)
What is the expected behavior?
I see three possible solutions:
- The documentation could warn that
mpl_draw()
does not work for multigraphs. mpl_draw()
could raise a warning when a multigraph is passed. (networkx seems to do that for at least the edge labels)- Ideally,
mpl_draw()
would be modified to show parallel edges. As far as I can see, this would include three steps, similar to what has been outlined in https://stackoverflow.com/a/70245742:- Modifying
draw_edges()
so it bends the arrows of parallel edges to prevent overlap. - Modifying
draw_edge_labels()
so it plots the edge labels at the positions of the arrows and not simply on the line connecting the nodes. - Modifying
draw_graph()
sokwds["edge_labels"]
contains one entry per edge and not one per node-pair. (The key of the dict should be the edge id and not the node pair.)
- Modifying
Steps to reproduce the problem
- Create a graph with two parallel edges:
graph = rustworkx.PyDiGraph()
graph.add_node('A')
graph.add_node('B')
graph.add_edge(0, 1, 1)
graph.add_edge(0, 1, 2)
mpl_draw(graph, with_labels=True, labels=str, edge_labels=str, alpha=0.5)
- Save the image as a vector graphic and inspect it.
The image will contain two arrows on top of each other and the label for edge 2. The label for edge 1 is not drawn.
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working