From 44d9fb068cb7090ec4bc76296cbef7dcb51f99a2 Mon Sep 17 00:00:00 2001 From: Ivan Carvalho <8753214+IvanIsCoding@users.noreply.github.com> Date: Fri, 15 Nov 2024 22:15:46 -0500 Subject: [PATCH] Fix bug where edge colors are randomly shuffled in `mpl_draw` (#1312) * Try to make edge_pos iteration deterministic * Fix minor bug * Add release note --- .../notes/correct-edge-colors-e082e1761e1c060b.yaml | 8 ++++++++ rustworkx/visualization/matplotlib.py | 5 +++-- 2 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 releasenotes/notes/correct-edge-colors-e082e1761e1c060b.yaml diff --git a/releasenotes/notes/correct-edge-colors-e082e1761e1c060b.yaml b/releasenotes/notes/correct-edge-colors-e082e1761e1c060b.yaml new file mode 100644 index 0000000000..b0df1801ee --- /dev/null +++ b/releasenotes/notes/correct-edge-colors-e082e1761e1c060b.yaml @@ -0,0 +1,8 @@ +--- +fixes: + - | + Fixed a bug introduced in version 0.15 where the edge colors specified as + a list in calls to :func:`~rustworkx.visualization.mpl_draw` were not + having their order respected. Instead, the order of the colors was + being shuffled. This has been restored and now the behavior should + match that of 0.14. \ No newline at end of file diff --git a/rustworkx/visualization/matplotlib.py b/rustworkx/visualization/matplotlib.py index 559756a13b..bd06c243b8 100644 --- a/rustworkx/visualization/matplotlib.py +++ b/rustworkx/visualization/matplotlib.py @@ -636,9 +636,10 @@ def draw_edges( edge_color = "k" # set edge positions - edge_pos = set() + edge_pos_keys = dict() for e in edge_list: - edge_pos.add((tuple(pos[e[0]]), tuple(pos[e[1]]))) + edge_pos_keys[(tuple(pos[e[0]]), tuple(pos[e[1]]))] = None + edge_pos = edge_pos_keys.keys() # Check if edge_color is an array of floats and map to edge_cmap. # This is the only case handled differently from matplotlib