-
Notifications
You must be signed in to change notification settings - Fork 106
/
Copy pathsgraph_show_with_vertex_coloring.py
37 lines (34 loc) · 2.13 KB
/
sgraph_show_with_vertex_coloring.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# Show an SGraph with custom vertex coloring
import graphlab as gl
import networkx as nx # Requires 'pip install networkx==1.9.1'
# We will use the "Tableau 20" color scheme as RGB triples scaled to 0-1
# See http://public.tableausoftware.com/profile/chris.gerrard#!/vizhome/TableauColors/ColorPaletteswithRGBValues
tableau20 = [[0.12156862745098039, 0.4666666666666667, 0.7058823529411765],
[0.6823529411764706, 0.7803921568627451, 0.9098039215686274],
[1.0, 0.4980392156862745, 0.054901960784313725],
[1.0, 0.7333333333333333, 0.47058823529411764],
[0.17254901960784313, 0.6274509803921569, 0.17254901960784313],
[0.596078431372549, 0.8745098039215686, 0.5411764705882353],
[0.8392156862745098, 0.15294117647058825, 0.1568627450980392],
[1.0, 0.596078431372549, 0.5882352941176471],
[0.5803921568627451, 0.403921568627451, 0.7411764705882353],
[0.7725490196078432, 0.6901960784313725, 0.8352941176470589],
[0.5490196078431373, 0.33725490196078434, 0.29411764705882354],
[0.7686274509803922, 0.611764705882353, 0.5803921568627451],
[0.8901960784313725, 0.4666666666666667, 0.7607843137254902],
[0.9686274509803922, 0.7137254901960784, 0.8235294117647058],
[0.4980392156862745, 0.4980392156862745, 0.4980392156862745],
[0.7803921568627451, 0.7803921568627451, 0.7803921568627451],
[0.7372549019607844, 0.7411764705882353, 0.13333333333333333],
[0.8588235294117647, 0.8588235294117647, 0.5529411764705883],
[0.09019607843137255, 0.7450980392156863, 0.8117647058823529],
[0.6196078431372549, 0.8549019607843137, 0.8980392156862745]]
# Add some example edges -- replace with your own graph
g = nx.dodecahedral_graph()
sg = gl.SGraph()
sg = sg.add_vertices([gl.Vertex(i) for i in g.nodes()])
sg = sg.add_edges([gl.Edge(*pair) for pair in g.edges()])
# Use graph coloring toolkit to apply colors
sg = gl.graph_coloring.create(sg)['graph']
colors = {v['__id']: tableau20[int(v['color_id'])] for v in sg.vertices}
sg.show(highlight=colors)