Color encodings tutorial#
See the examples below for common ways to map data to node/edge color in Graphistry.
Colors are often used with node size, icon, label, and badges to provide more visual information. Most encodings work both for points and edges. The PyGraphistry Python client makes it easier to use the URL settings API and the REST upload API. For dynamic control, you can use also use the JavaScript APIs.
Setup#
Mode api=3
is recommended. It is required for complex_encodings
(ex: .encode_point_color(...)
). Mode api=1
works with the simpler .bind(point_color='col_a')
form.
[ ]:
# ! pip install --user graphistry
import graphistry
# To specify Graphistry account & server, use:
# graphistry.register(api=3, username='...', password='...', protocol='https', server='hub.graphistry.com')
# For more options, see https://github.com/graphistry/pygraphistry#configure
graphistry.__version__
[ ]:
import datetime, pandas as pd
e_df = pd.DataFrame({
's': ['a', 'b', 'c', 'a', 'd', 'e'],
'd': ['b', 'c', 'a', 'c', 'e', 'd'],
'time': [datetime.datetime(1987, 10, 1), datetime.datetime(1987, 10, 2), datetime.datetime(1987, 10, 3),
datetime.datetime(1988, 10, 1), datetime.datetime(1988, 10, 2), datetime.datetime(1988, 10, 3)]
})
n_df = pd.DataFrame({
'n': ['a', 'b', 'c', 'd', 'e'],
'score': [ 0, 30, 50, 70, 90 ],
'palette_color_int32': pd.Series(
[0, 1, 2, 3, 4],
dtype='int32'),
'hex_color_int64': pd.Series(
[0xFF000000, 0xFFFF0000, 0xFFFFFF00, 0x00FF0000, 0x0000FF00],
dtype='int64'),
'type': ['mac', 'macbook', 'mac', 'macbook', 'sheep']
})
g = graphistry.edges(e_df, 's', 'd').nodes(n_df, 'n')
Colors#
Options: default, built-in palette, RGBA, continuous palette, and categorical mapping
Applies to both nodes and edges
Use the
.encode_point_color()
and.encode_edge_color()
callsFor palette and RGBA bindings (non-complex), you can also use the shorthand
.bind(point_color='col_a', edge_color='col_b')
.
Default#
Node: Graphistry looks at the local graph structure to auto-color nodes
Edges: Gradient from the src/dst node color to reinforce the node color decision
[ ]:
g.plot()
Built-in palette#
Bind an int32 column where values are intepreted by the predefined color palette tabble
[ ]:
print(g._nodes['palette_color_int32'].dtype)
g.encode_point_color('palette_color_int32').plot()
RGBA colors#
[ ]:
print(g._nodes['hex_color_int64'].dtype)
g.encode_point_color('hex_color_int64').plot()
Continuous colors#
Create a gradient effect by linearly mapping the input column to an evenly-spaced palette.
Great for tasks like mapping timestamps, counts, and scores to low/high and low/medium/high intervals.
[ ]:
g.encode_point_color('score', palette=['silver', 'maroon', '#FF99FF'], as_continuous=True).plot()
Categorical colors#
Map distinct values to specific colors. Optionally, set a default, else black.
[ ]:
g.encode_point_color(
'type',
categorical_mapping={
'mac': '#F99',
'macbook': '#99F'
},
default_mapping='silver'
).plot()
Edge colors#
Edge colors work the same as node colors by switching to call .encode_edge_color()
:
[ ]:
g.encode_edge_color('time', palette=['blue', 'red'], as_continuous=True).plot()
Legend support#
Categorical node colors will appear in legend when driven by column type
:
[ ]:
g.encode_point_color(
'type',
categorical_mapping={
'mac': '#F99',
'macbook': '#99F'
},
default_mapping='silver'
).plot()
[ ]: