Closed DionTimmermann closed 3 months ago
As a temporary workaround, you might want to try rustworkx.visualization.graphviz_draw
which does support multigraphs.
But indeed, we ported the visualization code from NetworkX. So we inherited the problems when drawing multigraphs.
As I worked on a rustworkx-related PR in last year's UnitaryHack, I'd like to work on this issue.
This is the graph I have obtained after a few edits in the matplotlib.py
file:
The code used to recreate this is:
import rustworkx
from rustworkx.visualization import mpl_draw
import matplotlib.pyplot as plt
graph = rustworkx.PyDiGraph()
graph.add_node('A')
graph.add_node('B')
graph.add_node('C')
graph.add_edge(1, 2, 4)
graph.add_edge(1, 0, 2)
graph.add_edge(0, 1, 3)
fig = mpl_draw(graph, with_labels=True, labels=str, edge_labels=str, alpha=0.5)
plt.savefig('test_fig.png')
Before moving forward, I wish to clarify a few points:
0
to 1
. Is this the expected behavior? connectionstyle
to either arc
or arc3
for this plotting style? Also, is it okay to keep rad
constant? I've used rad=0.25
.kwds["edge_labels"]
. Given that UnitaryHack concludes in less than a week, can someone please review my PR for any further changes required?
Information
What is the current behavior?
When plotting a multigraph with parallel edges using
rustworkx.visualization.mpl_draw()
, two issues occur:What is the expected behavior?
I see three possible solutions:
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)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:draw_edges()
so it bends the arrows of parallel edges to prevent overlap.draw_edge_labels()
so it plots the edge labels at the positions of the arrows and not simply on the line connecting the nodes.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.)Steps to reproduce the problem
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.