I have a filtered graph generated using graph-tool's GraphView()
.
g = gt.GraphView(g, vfilt= label_largest_component(g, directed=False))
The original graph g
has 10,069 vertices while the resulting graph has 9,197. However, using the new (filtered) graph, when I list the in-degrees using indeg = g.degree_property_map("in")
, the total number of elements in list(indeg.a)
is still 10,069. This becomes problematic when plotting the new filtered graph with 9,197 nodes where the vertex sizes are set as a function of indeg
, essentially because of the mismatched number of elements.
The code snippet looks like this
g = load_graph("ppnet.xml")
g = GraphView(g, vfilt=label_largest_component(g, directed=False))
indeg = g.degree_property_map("in")
indeg.a = np.sqrt(indeg.a) + 2
graph_draw(g, vertex_size = indeg, vertex_fill_color=indeg, pos = sfdp_layout(g),
vcmap=plt.cm.gist_heat, output_size=(400, 400), output="gc.png")
which when run, gives the following ValueError
ValueError: operands could not be broadcast together with shapes (10069,) (9197,)
What is the proper way to add the intended style for GraphView
objects?
Found a solution. I first created a copy of the
GraphView
object and then purged the vertices of this copy. Note that instead of retaining the variable nameg
, I introduced a new variablegc
for clarity.