"vertex_label_angle" and "vertex_label_dist" are not working in Python with matplotlib backend

Hi

I was trying to use the “vertex_label_dist” and “vertex_label_angle” to adjust the position of vertex labels, but it seems they are not working with matplotlib backend. I also tried to use cairo backend and they work fine in cairo backend. I attached the plots and my code here. I wonder whether there is problem in my code or the two settings are not available for matplotlib backend.

Plot of cairo:

Plot of matplotlib:

Code:

    # Construct a graph with 3 vertices
    n_vertices = 5
    edges = [(0, 1), (0, 2), (0, 3), (0, 4), (1, 2), (1, 3), (1, 4), (3, 4)]
    g = ig.Graph(n_vertices, edges)

    # Set attributes for the graph, nodes, and edges
    g["title"] = "Small Social Network"
    g.vs["name"] = ["Daniel Morillas", "Kathy Archer", "Kyle Ding", "Joshua Walton", "Jana Hoyer"]
    g.vs["gender"] = ["M", "F", "F", "M", "F"]
    g.es["married"] = [False, False, False, False, False, False, False, True]

    # Set individual attributes
    g.vs[1]["name"] = "Kathy Morillas"
    g.es[0]["married"] = True

    fig, ax = plt.subplots(figsize=(5, 5))

    visual_style = {"vertex_size": 15,
                    "vertex_color": "lightblue",
                    "vertex_label": g.vs["name"],
                    "vertex_label_angle": 3,
                    "vertex_label_dist": 20,
                    "edge_width": 2,
                    "vertex_frame_color": "black",
                    "layout": "circle",
                    "margin": 0.8}

    ig.plot(
        g,
        # target=ax,
        **visual_style
    )
    plt.show()

    # Export and import a graph as a GML file.
    g.save("social_network.gml")
    g = ig.load("social_network.gml")
1 Like

@iosonofabio, this question seems to be right up your alley. I can imagine that this is already addressed in the development version?

Hi vtraag

I used the development version installed by pip install git+https://github.com/igraph/python-igraph@develop

It seems the vertex labels are still static with different “vertex_label_dist” and “vertex_label_angle” values.

Yes, it may happen that the Matplotlib backend does not support all the features yet that used to be supported in the Cairo backend. @iosonofabio is on paternal leave so I’m not sure whether he’ll be able to tackle this in the near future. Please file an issue on Sign in to GitHub · GitHub and we’ll add this to the backlog. (And of course, if you manage to solve this on your own, we always welcome PRs).

Easy to fix, two lines of code. Would you like to try making a PR? If not I’ll take it, but it might take a while

any progress here? thx