2

I'm testing igraph python to plot undirected graph. The problem is that the labels get cuttoff for some reasons. The labels contain spaces, so I had to replace the spaces with underscore.

For examples: If the label is Mike_Jorden then only e_jorde is showing and sometimes ike_jorde.

My input is a csv file formatted as N_Col for examples as an input:

Mike_Jorden Test_2
Test_2 Test_1
Test_1 Mike_Jorden

My code is as follow:

from igraph import *

g = Graph.Read_Ncol("graph.csv", directed=False)
names = g.vs["name"]

# remove double quotes 
for i in range(len(names)):
    names[i] = names[i][1:-1]

layout = g.layout("kk")
visual_style = {}
visual_style["vertex_shape"] = 'rectangle'
visual_style["vertex_size"] = g.betweenness()
visual_style["layout"] = layout
visual_style["bbox"] = (1000,1000)
visual_style["label_size"] = 20
visual_style["margin"] = 20
visual_style["label_dist"] = 20
visual_style["vertex_label"] = names 

plot(g ,"test.pdf",**visual_style)

I tried different layout algorithms but I still get the same issue. Any advice please.

MikeAlbert
  • 164
  • 2
  • 11

2 Answers2

1

Spyder doesn't seem to show labels. Spyder output image

Jupyter can show the labels. Jupyter output image

stok
  • 340
  • 4
  • 8
0

I just tried a simple example with long vertex names. The plot works fine. Try to use g.vs['label'] to assign names to vertices.

Example:

from igraph import *

g=Graph.Tree(10,2)
g.vs['label'] = 'Mike John Mary George NICK'
plot(g)

The results is the following: This

seralouk
  • 22,948
  • 5
  • 82
  • 101