Skip to content

rx.visualization.mpl_draw() does not apply an edge_color list to the correct edges #1308

@ryanhill1

Description

@ryanhill1

Information

  • rustworkx version: 0.15.1
  • Python version: 3.11.9
  • Rust version: N/A
  • Operating system: Ubuntu 20.04

What is the current behavior?

rustworkx.visualization.matplotlib.draw_edges() does not correctly apply edge_color of type list. Edge colors are not being applied to the edges of graph.edge_list() in the correct order. Issue sourced from: qBraid/qBraid#802

What is the expected behavior?

The entries of a given edge_color list should be mapped to the correct edges, corresponding to the order of graph.edge_list().

Steps to reproduce the problem

The code below plots 3 nodes and 3 edges. Edge (c, a) should be colored blue. But if you run the code multiple times, you will find that the blue edge changes, and is not always (c, a).

import matplotlib.pyplot as plt
import rustworkx as rx
from rustworkx.visualization import mpl_draw

graph = rx.PyDiGraph()

a = graph.add_node("A")
b = graph.add_node("B")
c = graph.add_node("C")

graph.add_edges_from([(a, b, 0.1), (b, c, 1.2), (c, a, 2.0)])

edge_colors_dict = {(c, a): "blue"}
edge_colors = [edge_colors_dict.get((u, v), "grey") for u, v in graph.edge_list()]

mpl_draw(graph, edge_color=edge_colors, with_labels=True, labels=str)

plt.show()

If you pip install rustworkx<0.15.0, and run the code again, it works fine.

Therefore, I was able to trace this bug back the following commit: 646057a

Using the draw_edges() function from before that commit (i.e. rustworkx version 0.14.2) resolves the issue. But the latest update seems to form an arrow_color list that is not consistent with the indexing of the edge_color list.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions