Graph visualization in the Neptune workbench - Amazon Neptune

Graph visualization in the Neptune workbench

In many cases the Neptune workbench can create a visual diagram of your query results as well as returning them in tabular form. The graph visualization is available in the Graph tab in the query results whenever visualization is possible.


To get access to recently added functionality and fixes in notebooks that you are already using, first stop and then re-start your notebook instance.

Visualizing Gremlin query results

Neptune workbench creates a visualization of the query results for any Gremlin query that returns a path. To see the visualization, select the Graph tab to the right of the Console tab under the query after you run it.

You can use query visualization hints to control how the visualizer diagrams query output. These hints follow the %%gremlin cell magic and are preceded by the --path-pattern (or its short form, -p) parameter name:

%%gremlin -p comma-separated hints

You can also use the --group-by (or -g) flag to specify a property of the vertices to group them by. This allows specifying a color or icon for different groups of vertices.

The names of the hints reflect the Gremlin steps commonly used when traversing between vertices, and they behave accordingly. Multiple hints can be used in combination, separated by commas, without any spaces between them. The hints used should match the corresponding Gremlin steps in the query being visualized. Here is an example:

%%gremlin -p v,oute,inv g.V().hasLabel('airport').outE().inV().path().by('code').by('dist').limit(5)

Available visualization hints are as follows:

v inv outv e ine oute

Here are some examples of graph visualizations using groups:

Examples of Gremlin graph visualizations

Visualizing SPARQL query results

Neptune workbench creates a visualization of the query results for any SPARQL query that takes either one of these forms:

  • SELECT ?subject ?predicate ?object

  • SELECT ?s ?p ?o

To see the visualization, select the Graph tab to the right of the Table tab under the query after you run it.

By default, a SPARQL visualization only includes triple patterns where the o? is a uri or a bnode (blank node). All other ?o binding types such as literal strings or integers are treated as properties of the ?s node that can be viewed using the Details pane in the Graph tab.

In many cases, however, you may want to include such literal values as vertices in the visualization. To do that, use the --expand-all query hint after the %%sparql cell magic:

%%sparql --expand-all

This tells the visualizer to include all ?s ?p ?o results in the graph diagram regardless of binding type.

You can see this hint used throughout the Air-Routes-SPARQL.ipynb notebook and you can experiment by running the queries with and without the hint to see what difference it makes in the visualization.

Accessing visualization tutorial notebooks in the Neptune workbench

The two visualization tutorial notebooks that come with the Neptune workbench provide a wealth of examples in Gremlin and in SPARQL of how to query graph data effectively and visualize the results.

Navigate to the Visualization notebooks

  1. In the navigation pane on the left, choose the Open Notebook button to the right.

  2. Once the Neptune workbench opens, running Jupyter, you will see a Neptune folder at the top level. Choose it to open the folder.

  3. At the next level is a folder named 02-Visualization. Open this folder. Inside are several notebooks that walk you through different ways to query your graph data, in Gremlin and in SPARQL, and how to visualize the query results:

    Select a notebook to experiment with the queries it contains.