Change color of a node in a Neo4j graph

Asked

Viewed 182 times

0

I created an example graph in Neo4j with a father and two children. I would like to know how to change the color of all nodes that have the level 1.

inserir a descrição da imagem aqui

When I click on the node appears at the bottom to modify the size and color but the change affects everyone and not just the ones that have the value of level 1. Some images I found on the web show the nodes with different colors but I didn’t find how to apply this, neither via the interface nor using the py2neo(Python) lib I am using. My code is like this:

from py2neo import Graph, Path
from py2neo import Node
from py2neo import Relationship

graph = Graph('http://neo4j:senha_falsa@localhost:7474/db/data/')
graph.delete_all()

a = Node("Conta", email="[email protected]", name="Argos", nivel="0")
b = Node("Conta", email="[email protected]", name="Riana", nivel="1")
c = Node("Conta", email="[email protected]", name="Elias", nivel="1")

graph.create(Relationship(a, "PAI DE", b))
graph.create(Relationship(a, "PAI DE", c))

I wanted to know if there’s no way to pass size and color as attributes.

1 answer

1


@rodrigorf, these options of size and color of the nodes that you refer to are related only to how the Neoj4 Browser presents the result of your Cypher queries. That is, there is no relation between these presentation options and the Python language or the py2neo library. So you won’t be able to change them through these.

In addition, the option offered by the Neo4j Browser that allows changing the color of nodes is related to the label (label) of these nodes. Thus, you will be able to change the color of your nodes according to the label of each one. For example: you can define all nodes with label :User are red and all nodes with label :Product be blue.

If you are looking for a preview option that gives you more flexibility in presentation options, I suggest you take a look at this link where some Neo4j-compatible graph visualization libraries are presented.

  • Bruno, so for me to have the desired effect inside the Neo4j Browser I need to at least set some attribute with a specific label to can change the color of all nodes that have that same label correct? Already solve my problem for now, I’ll read the link you sent and see if I can do something inside the code in python to perpetuate these visual settings. thank you

  • This, you will only be able to assign a color to nodes that have a label. Nodes with the same label will have the same color. The most you can do through Python is to create the nodes with the Abels. Arrange!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.