如何在python igraph中的绘图中保留顶点标签

时间:2019-04-17 12:28:23

标签: python igraph

我有一个igraph

g = igr.Graph([(0,1), (0,2), (2,3), (3,4), (4,2), (2,5), (5,0), (6,3), (5,6)])
g.vs["name"] = ["Alice", "Bob", "Claire", "Dennis", "Esther", "Frank", "George"]
g.vs["age"] = [25, 31, 18, 47, 22, 23, 50]
g.vs["gender"] = ["f", "m", "f", "m", "f", "m", "m"]
g.es["is_formal"] = [False, False, True, True, True, False, True, False, False]

layout = g.layout("rt")

g.vs["label"] = g.vs["name"] #assign each node label to the name
color_dict = {"m": "blue", "f": "pink"} #create a colour dictionary
g.vs["color"] = [color_dict[gender] for gender in g.vs["gender"]] #apply dictionary to each node
visual_style = {}
visual_style["vertex_size"] = 20
visual_style["vertex_color"] = [color_dict[gender] for gender in g.vs["gender"]]
visual_style["vertex_label"] = g.vs["name"]
visual_style["vertex_label_dist"] = 1
visual_style["vertex_label_angle"] = 3

visual_style["edge_width"] = [1 + 2 * int(is_formal) for is_formal in g.es["is_formal"]]
visual_style["layout"] = layout
visual_style["bbox"] = (400, 400)
visual_style["margin"] = 20
visual_style["vertex_label_angle"]=0
igr.plot(g, **visual_style)

enter image description here

,但顶点标签不在绘图区域内。即弗兰克被切断了。 有没有办法确保所有标签都留在绘图区域内?

我尝试进行调整(按照手册进行(调整中心距和弧度角的距离))

visual_style["vertex_label_dist"] = 1
visual_style["vertex_label_angle"] = 3

无济于事。

我也尝试过运行不同的布局,但是通常会在绘图区域之外打印一个顶点标签。

欢迎提出任何建议。

1 个答案:

答案 0 :(得分:0)

调整

Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: The column name ZoneId33_57_0_ is not valid.