From 602046fb6748212c50cdf81d04b11eb5106c07fd 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 (cherry picked from commit 44d9fb068cb7090ec4bc76296cbef7dcb51f99a2) # Conflicts: # rustworkx/visualization/matplotlib.py --- .../notes/correct-edge-colors-e082e1761e1c060b.yaml | 8 ++++++++ rustworkx/visualization/matplotlib.py | 7 +++++++ 2 files changed, 15 insertions(+) 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 000000000..b0df1801e --- /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 7f1437112..53f00704b 100644 --- a/rustworkx/visualization/matplotlib.py +++ b/rustworkx/visualization/matplotlib.py @@ -636,7 +636,14 @@ def draw_edges( edge_color = "k" # set edge positions +<<<<<<< HEAD edge_pos = np.asarray([(pos[e[0]], pos[e[1]]) for e in edge_list]) +======= + edge_pos_keys = dict() + for e in edge_list: + edge_pos_keys[(tuple(pos[e[0]]), tuple(pos[e[1]]))] = None + edge_pos = edge_pos_keys.keys() +>>>>>>> 44d9fb0 (Fix bug where edge colors are randomly shuffled in `mpl_draw` (#1312)) # Check if edge_color is an array of floats and map to edge_cmap. # This is the only case handled differently from matplotlib