I am trying to learn how to plot different edges with different thickness in igraph. I have tried the tutorial example at Maximum Bipartite Matching but it fails. The code is:
import igraph as ig
import matplotlib.pyplot as plt
# Assign nodes 0-4 to one side, and the nodes 5-8 to the other side
g = ig.Graph.Bipartite(
[0, 0, 0, 0, 0, 1, 1, 1, 1],
[(0, 5), (1, 6), (1, 7), (2, 5), (2, 8), (3, 6), (4, 5), (4, 6)]
)
assert g.is_bipartite()
matching = g.maximum_bipartite_matching()
matching = g.maximum_bipartite_matching()
# Print pairings for each node on one side
matching_size = 0
print("Matching is:")
for i in range(5):
print(f"{i} - {matching.match_of(i)}")
if matching.is_matched(i):
matching_size += 1
print("Size of maximum matching is:", matching_size)
fig, ax = plt.subplots(figsize=(7, 3))
ig.plot(
g,
target=ax,
layout=g.layout_bipartite(),
vertex_size=0.4,
vertex_label=range(g.vcount()),
vertex_color="lightblue",
edge_width=[3 if e.target == matching.match_of(e.source) else 1.0 for e in g.es],
edge_color=["red" if e.target == matching.match_of(e.source) else "black" for e in g.es]
)
plt.show()
The first failure is:
ValueError: RGBA sequence should have length 3 or 4
which is caused by the edge_color
line but if you comment it out the edge_width
line also fails as that variable is expected to be an int not a list.
How can this code be fixed?