I have a directed graph which is filled and displayed in the following way:
def visualize_relations(self, relations: List[Relation]) -> None:
extracted_triplets = []
for relation in relations:
triplet = [relation.from_item.identifier, relation.connecting_property.identifier, relation.to_item.identifier]
extracted_triplets.append(triplet)
g = Graph(directed=True)
for triplet in extracted_triplets:
subj_vertex = self.add_or_find_vertex(g, triplet[0])
obj_vertex = self.add_or_find_vertex(g, triplet[2])
g.add_edge(subj_vertex, obj_vertex, uri=triplet[1], label=triplet[1])
visual_style = {}
colours = ['#fecc5c', '#a31a1c']
visual_style["bbox"] = (4000, 4000)
visual_style["margin"] = 300
visual_style["vertex_color"] = 'grey'
visual_style["vertex_size"] = 300
visual_style["vertex_label_size"] = 100
visual_style["edge_curved"] = False
my_layout = g.layout_fruchterman_reingold()
visual_style["layout"] = my_layout
plot(g, **visual_style)
plot(g, "output/visualize_relations.png", **visual_style)
def add_or_find_vertex(self, g, uri):
try:
return g.vs.find(name=uri)
except (KeyError, ValueError):
g.add_vertex(name=uri, label=uri)
return g.vs.find(name=uri)
I would like to make each node’s size on the plot analogous to the number of incoming connections it has. How could I do that? Note that the graphs I’m planning to plot will not be too large, and therefore I don’t mind more computationally intensive solutions.
igraph-python version: 0.8.3
OS: Windows 10
Python 3.8