Getting started
In this section, we will cover the very basics of creating a visualization graph using the neo4j-viz library.
We will use a small toy graph representing the purchase history of a few people and products.
To follow along with the example below, please make sure you have installed the library first.
We start by instantiating the Nodes and Relationships we want in our graph. The only mandatory fields for a node are the “id”, and “source” and “target” for a relationship. But the other fields can optionally be used to customize the appearance of the nodes and relationships in the visualization.
Lastly we create a VisualizationGraph object with the nodes and relationships we created, and call its render method to display the graph.
from neo4j_viz import Node, Relationship, VisualizationGraph
nodes = [
Node(id=0, size=10, caption="Person"),
Node(id=1, size=10, caption="Product"),
Node(id=2, size=20, caption="Product"),
Node(id=3, size=10, caption="Person"),
Node(id=4, size=10, caption="Product"),
]
relationships = [
Relationship(
source=0,
target=1,
caption="BUYS",
),
Relationship(
source=0,
target=2,
caption="BUYS",
),
Relationship(
source=3,
target=2,
caption="BUYS",
),
]
VG = VisualizationGraph(nodes=nodes, relationships=relationships)
VG.render(initial_zoom=2)
|
See the Jupyter notebook to interact with the graph. |
As we can see in the graph above, the radius of one of the nodes is larger than the others. This is because we set the “size” field of the node to 20, while the others are set to 10.
At this time all nodes have the same color.
If we want to distinguish between the different types of nodes, we can color them differently with the color_nodes method.
We can pass the field we want to use to color the nodes as an argument.
In this case, we will use the "caption" field.
Nodes with the same "caption" will have the same color.
We will use the default color scheme, which is the Neo4j color scheme.
VG.color_nodes(field="caption")
VG.render(initial_zoom=2)
|
See the Jupyter notebook to interact with the graph. |
We are now easily able to distinguish between the different types of nodes in the graph.
Next steps
Now that we have covered the basics of creating and rendering a visualization graph, we can move on to more advanced topics.
Here are some suggestions for what to do next:
-
Browse the notebook examples for more examples and use cases
-
Learn about the integrations with other libraries such as Neo4j GDS and Pandas
-
Check out the rendering options and convenience methods of
VisualizationGraph -
Read about our API reference