for e in g.edges():
ep_filter[e] = g.edge_properties['layer'][e] == layer
_______________________________________________Hi all,
gt allows creating graph views where vertices and/or edges are filtered out. The principle is described in the documentation:
"Vertices or edges which are to be filtered should be marked with a PropertyMap with value type bool, and then set with set_vertex_filter() or set_edge_filter() methods. By default, vertex or edges with value '1' are kept in the graphs, and those with value '0' are filtered out." (https://graph-tool.skewed.de/static/doc/quickstart.html#graph-filtering)
Given a layered graph, where layers are coded via an edge property, I want to draw the graphs layer by layer.
This is an example graph:
from graph_tool.all import *
import numpy as np
import pandas as pd
# data
edge_list = pd.DataFrame(np.array([[0, 1, 0], [1, 2, 1], [2, 0, 2]]), columns=['i', 'j', 'layer'])
# create graph
g = Graph(directed=False)
ep_layer = g.new_edge_property('int')
g.add_edge_list(edge_list.values, eprops=[ep_layer])
g.edge_properties['layer'] = ep_layer
# draw graph with edge colors showing the layers
graph_draw(g, edge_color=g.ep.layer)
It is possible to draw a single layer (in this example layer 0) in this complicated way:
# set layer to be drawn
layer = 0
# create graph view
ep_filter = g.new_edge_property('bool')
for i in range(0, len(edge_list)):
e = g.edge(edge_list['i'][i], edge_list['j'][i])
if edge_list['layer'][i] == layer:
ep_filter[e] = True
else:
ep_filter[e] = False
g_filter = GraphView(g, efilt=ep_filter)
# draw filtered graph
graph_draw(g_filter, edge_color=g.ep.layer)
If I proceed this way I will also have to create a vertex property map to filter unused vertices and do these steps for all layers I want to draw.
But isn’t there a more elegant way – preferably handling vertices and edges in the same step?
Many thanks and best wishes
Haiko
graph-tool mailing list
graph-tool@skewed.de
https://lists.skewed.de/mailman/listinfo/graph-tool