2

How can I set the background color of a vertex?

I know there should be a property dictionary or something but I can't find an example.

I need it to color different kind of vertices in a bipartite graph:

gtdraw.graph_draw(g, pos=pos, 
                  vertex_fill_color=part, 
                  vertex_font_size=6, 
                  output_size=(5000, 5000), 
                  output="img/pic.png")
Stefan Falk
  • 23,898
  • 50
  • 191
  • 378

3 Answers3

3

By background color of the vertex, i'm assuming you mean vertex_fill_color property.

The following code is taken from here

# Normalised RGB color.
# 0->Red, 1->Blue
red_blue_map = {0:(1,0,0,1),1:(0,0,1,1)}
# Create new vertex property
plot_color = g.new_vertex_property('vector<double>')
# add that property to graph
g.vertex_properties['plot_color'] = plot_color
# assign a value to that property for each node of that graph
for v in g.vertices():
    plot_color[v] = red_blue_map[g.vertex_properties['value'][v]]

gt.graph_draw(g,
              vertex_fill_color=g.vertex_properties['plot_color'])

The code is self explanatory.

2

A complete list of vertex properties can be found here. I am unsure of what you mean by 'background color'. If you want to add a halo effect on the vertices, you can set vertex_halo to True and use vertex_halo_color and vertex_halo_size to control the effect. If you just want to change the color of the vertex or the outline, you can use vertex_color and vertex_fill_color like you already are.

Ben Longo
  • 124
  • 1
  • 15
1

You can set the background color with the keyword argument vertex_fill_color, as you do it. Just check that part stores the vertex properties associated with the bipartite information (i.e. which part).

For a simple example you can take a look at the end of An Example: Building a Price Network which show how to draw a network where the vertex colors represent the age of the vertex, from older (red) to newer (black). Here is the illustration taken from this graph-tool example:

enter image description here

I hope this will help you.

Flabetvibes
  • 3,066
  • 20
  • 32