# How to change thickness of individual edges (tutorial seems broken)

**URL:** <https://igraph.discourse.group/t/how-to-change-thickness-of-individual-edges-tutorial-seems-broken/1164>\
**Category:** Usage\
**Tags:** Python\
**Created:** [31 March 2022 15:06 UTC](https://igraph.discourse.group/t/how-to-change-thickness-of-individual-edges-tutorial-seems-broken/1164 "2022-03-31T15:06:30Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![lesshaste](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/lesshaste/32/740_2.png) [@lesshaste](https://igraph.discourse.group/u/lesshaste)\
**Post date:** [31 March 2022 15:06 UTC](https://igraph.discourse.group/t/how-to-change-thickness-of-individual-edges-tutorial-seems-broken/1164/1 "2022-03-31T15:06:30Z")

</div>

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](https://igraph.org/python/tutorial/develop/tutorials/bipartite_matching/bipartite_matching.html) 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?

---

<div class="post-metadata">

**Author:** ![szhorvat](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/szhorvat/32/3_2.png) [@szhorvat](https://igraph.discourse.group/u/szhorvat)\
**Post date:** [31 March 2022 15:45 UTC](https://igraph.discourse.group/t/how-to-change-thickness-of-individual-edges-tutorial-seems-broken/1164/2 "2022-03-31T15:45:33Z")

</div>

These tutorials were written for the development version of igraph, not yet released. They should work correctly if you install the development version from the `develop` branch. See here:

> **[GitHub - igraph/python-igraph: Python interface for igraph](https://github.com/igraph/python-igraph/#compiling-the-development-version)**
>
> Python interface for igraph. Contribute to igraph/python-igraph development by creating an account on GitHub.

You will need to compile the package yourself, which is straightforward on Linux/macOS, but may be some trouble on Windows.

---

<div class="post-metadata">

**Author:** ![lesshaste](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/lesshaste/32/740_2.png) [@lesshaste](https://igraph.discourse.group/u/lesshaste)\
**Post date:** [31 March 2022 15:47 UTC](https://igraph.discourse.group/t/how-to-change-thickness-of-individual-edges-tutorial-seems-broken/1164/3 "2022-03-31T15:47:30Z")

</div>

I had no idea. That is a little confusing as it says " [python-igraph 0.9.9]" in the top left of the web page.

How can the code be made to work with python-igraph 0.9.9?

---

<div class="post-metadata">

**Author:** ![szhorvat](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/szhorvat/32/3_2.png) [@szhorvat](https://igraph.discourse.group/u/szhorvat)\
**Post date:** [31 March 2022 16:02 UTC](https://igraph.discourse.group/t/how-to-change-thickness-of-individual-edges-tutorial-seems-broken/1164/4 "2022-03-31T16:02:39Z")

</div>

@iosonofabio @tamas Can you confirm that this tutorial page belongs to the develop version? That’s what the URL suggests. How did the 0.9.9 (and also 0.9.8!) version number get into the develop docs?

---

<div class="post-metadata">

**Author:** ![tamas](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/tamas/32/1261_2.png) [@tamas](https://igraph.discourse.group/u/tamas)\
**Post date:** [1 April 2022 09:32 UTC](https://igraph.discourse.group/t/how-to-change-thickness-of-individual-edges-tutorial-seems-broken/1164/5 "2022-04-01T09:32:05Z")

</div>

Yes, the tutorial (and in fact the entire “Tutorial gallery” section) belongs to the development version, so that’s a bug on the homepage. A tell-tale sign that something is wrong is that the version switcher dropdown disappears from the header of the page that was originally linked to. I’ll look into this.

If you’d like to fix the example for the officially released version, you need to switch back to the Cairo plotting backend from Matplotlib as the Matplotlib backend in 0.9.9 does not support per-edge colors yet. Something like this will work (note that the vertex size changed as Cairo units are different):

```auto
print("Size of maximum matching is:", matching_size)

# No matplotlib figure creation here
# fig, ax = plt.subplots(figsize=(7, 3))

ig.plot(
    g,
    layout=g.layout_bipartite(),
    vertex_size=20,
    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]
)

```

---

<div class="post-metadata">

**Author:** ![lesshaste](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/lesshaste/32/740_2.png) [@lesshaste](https://igraph.discourse.group/u/lesshaste)\
**Post date:** [1 April 2022 16:09 UTC](https://igraph.discourse.group/t/how-to-change-thickness-of-individual-edges-tutorial-seems-broken/1164/6 "2022-04-01T16:09:55Z")

</div>

> [@tamas](#):
>
> ```auto
> ig.plot(
> g,
> layout=g.layout_bipartite(),
> vertex_size=20,
> 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]
> )
> 
> ```

Thank you so much! This is very helpful.
