Examples
Graph Visualization
Visualize your graph in Jupyter notebooks or as HTML files.
CogDB can render your graph as an interactive visualization.
Creating a Graph
from cog.torque import Graph
g = Graph("people")
g.put("alice", "follows", "bob")
g.put("bob", "follows", "fred")
g.put("bob", "status", "cool_person")
g.put("charlie", "follows", "bob")
g.put("charlie", "follows", "dani")
g.put("dani", "follows", "bob")
g.put("dani", "follows", "greg")
g.put("dani", "status", "cool_person")
g.put("emily", "follows", "fred")
g.put("fred", "follows", "greg")
g.put("greg", "status", "cool_person")Visualizing in Jupyter
Use view() and render() to visualize relationships:
g.v().tag("from").out("follows").tag("to").view("follows").render()render() works in Jupyter notebooks. Otherwise use view(..).url to get the HTML file path.

Visualization Steps
tag("from")- Tag the source nodes.out("follows")- Traverse the relationshiptag("to")- Tag the destination nodes.view("follows")- Create a view with the edge label.render()- Render in Jupyter
Required Tags for Rendering
When using .view() to render graph visualizations, you must use specific tag names:
| Tag Name | Purpose |
|---|---|
from | Identifies the source node of each edge |
to | Identifies the target node of each edge |
The graph visualization reads the from and to properties from each result to construct nodes and edges.
Important Notes:
- Tag names are case-sensitive - use lowercase
fromandto - Both tags are required - the view needs both to draw edges between nodes
- Order matters -
fromshould mark the source vertex andtoshould mark the destination vertex in your traversal - Other tags are ignored - you can add additional tags (e.g.,
tag("source")), but onlyfromandtoare used for rendering
Export to HTML
Outside of Jupyter, get the HTML file path:
viz = g.v().tag("from").out("follows").tag("to").view("follows")
print(viz.url) # Path to the HTML file