You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/source/customizing.rst
+42-8Lines changed: 42 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -36,19 +36,34 @@ The ``color_nodes`` method
36
36
37
37
By calling the :meth:`neo4j_viz.VisualizationGraph.color_nodes` method, you can color nodes based on a
38
38
node property (field).
39
-
This method will give a distinct color (if possible) to each unique value of the node ``property`` that you provide as
40
-
the first positional argument.
39
+
It's possible to color the nodes based on a discrete or continuous property.
40
+
In the discrete case, a new color from the ``colors`` provided is assigned to each unique value of the node property.
41
+
In the continuous case, the ``colors`` should be a list of colors representing a range that are used to create a gradient of colors based on the values of the node property.
41
42
42
43
By default the Neo4j color palette that works for both light and dark mode will be used.
43
44
If you want to use a different color palette, you can pass a dictionary or iterable of colors as the ``colors``
44
45
parameter.
45
46
A color value can for example be either strings like "blue", or hexadecimal color codes like "#FF0000", or even a tuple of RGB values like (255, 0, 255).
46
-
Here is an example of providing a list of custom colors to the ``color_nodes`` method:
47
+
48
+
If some nodes already have a ``color`` set, you can choose whether or not to override it with the ``override``
49
+
parameter.
50
+
51
+
52
+
By discrete node property (field)
53
+
*********************************
54
+
55
+
To not use the default colors, we can provide a list of custom colors based on the discrete node property (field) "caption" to the ``color_nodes`` method:
The full set of allowed values for colors are listed `here <https://docs.pydantic.dev/2.0/usage/types/extra_types/color_types/>`_.
54
69
@@ -60,7 +75,7 @@ this snippet:
60
75
from palettable.wesanderson import Moonrise1_5
61
76
62
77
# VG is a VisualizationGraph object
63
-
VG.color_nodes("caption", Moonrise1_5.colors)
78
+
VG.color_nodes("caption", Moonrise1_5.colors)# PropertyType.DISCRETE is default
64
79
65
80
In this case, all nodes with the same caption will get the same color.
66
81
@@ -69,12 +84,31 @@ To avoid that, you could use another palette or extend one with additional color
69
84
:doc:`Visualizing Neo4j Graph Data Science (GDS) Graphs tutorial <./tutorials/gds-example>` for an example on how
70
85
to do the latter.
71
86
72
-
If some nodes already have a ``color`` set, you can choose whether or not to override it with the ``override``
73
-
parameter.
87
+
88
+
By continuous node property (field)
89
+
***********************************
90
+
91
+
To not use the default colors, we can provide a list of custom colors representing a range to the ``color_nodes`` method:
92
+
93
+
.. code-block:: python
94
+
95
+
from neo4j_viz.colors import PropertyType
96
+
97
+
# VG is a VisualizationGraph object
98
+
VG.color_nodes(
99
+
"centrality_score",
100
+
[(255, 0, 0), (191, 64, 0), (128, 128, 0), (64, 191, 0), (0, 255, 0)] # From red to green
101
+
property_type=PropertyType.CONTINUOUS
102
+
)
103
+
104
+
In this case, the nodes will be colored based on the value of the "centrality_score" property, with the lowest values being colored red and the highest values being colored green.
105
+
Since we only provided five colors in the range, the granularity of the gradient will be limited to five steps.
106
+
107
+
`palettable` and `matplotlib` are great libraries to use to create custom color gradients.
74
108
75
109
76
110
Sizing nodes
77
-
--------------
111
+
------------
78
112
79
113
Nodes can be given a size directly by providing them with a size property, upon creation.
80
114
This can for example be done by passing a size as an integer to the ``size`` parameter of the
0 commit comments