Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # coding: utf-8
- import math
- from bokeh.io import show, output_file
- from bokeh.plotting import figure
- from bokeh.models import GraphRenderer, StaticLayoutProvider, Oval
- from bokeh.palettes import Spectral8
- N = 8
- node_indices = list(range(N))
- plot = figure(title="Graph Layout Demonstration", x_range=(-1.1,1.1), y_range=(-1.1,1.1),
- plot_width=250, plot_height=250,
- tools="", toolbar_location=None)
- graph = GraphRenderer()
- graph.node_renderer.glyph = Oval(height=0.1, width=0.2, fill_color="color")
- graph.node_renderer.data_source.data = dict(
- index=node_indices,
- color=Spectral8
- )
- graph.node_renderer.data_source.name = "Node Renderer"
- graph.edge_renderer.data_source.data = dict(
- start=[0]*N,
- end=node_indices)
- graph.edge_renderer.data_source.name = "Edge Renderer"
- ### start of layout code
- circ = [i*2*math.pi/8 for i in node_indices]
- x = [math.cos(i) for i in circ]
- y = [math.sin(i) for i in circ]
- graph_layout = dict(zip(node_indices, zip(x, y)))
- graph.layout_provider = StaticLayoutProvider(graph_layout=graph_layout)
- plot.renderers.append(graph)
- #output_file("graph.html")
- show(plot)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement