# Querying and visualization with Jupyter notebook

**URL:** <https://discuss.dgraph.io/t/querying-and-visualization-with-jupyter-notebook/6834>\
**Category:** Dgraph\
**Created:** [May 26, 2020, 8:05am UTC](https://discuss.dgraph.io/t/querying-and-visualization-with-jupyter-notebook/6834 "2020-05-26T08:05:34Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![pirxthepilot](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/pirxthepilot/32/4106_2.png) [@pirxthepilot](https://discuss.dgraph.io/u/pirxthepilot)\
**Post date:** [May 26, 2020, 8:05am UTC](https://discuss.dgraph.io/t/querying-and-visualization-with-jupyter-notebook/6834/1 "2020-05-26T08:05:34Z")

</div>

Hello, I’m looking to integrate a DGraph database with a Jupyter Notebook where we can query data from the db with visualizations. On the viz side one of the most promising I’ve seen so far is pygraphistry ([GitHub - graphistry/pygraphistry: PyGraphistry is a Python library to quickly load, shape, embed, and explore big graphs with the GPU-accelerated Graphistry visual graph analyzer](https://github.com/graphistry/pygraphistry)). It doesn’t provide Dgraph support out of the box but I was thinking transforming the dgraph JSON output into a Pandas dataframe which pygraphistry can then process. Is this a reasonable way to approach it, or maybe there is a better one?

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![Anurag](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/anurag/32/2599_2.png) [@Anurag](https://discuss.dgraph.io/u/Anurag)\
**Post date:** [May 26, 2020, 9:53am UTC](https://discuss.dgraph.io/t/querying-and-visualization-with-jupyter-notebook/6834/2 "2020-05-26T09:53:16Z")

</div>

Hi @pirxthepilot, welcome to Dgraph!  
Have you tried Ratel for visualization? You can check it out here in the [playground](https://play.dgraph.io/?latest) and [github](https://github.com/dgraph-io/ratel) to build locally. But I don’t think there is a easy way to connect Ratel with Jupyter notebooks yet. What is your use case in terms of the data size and kind of queries you wish to visualize.

---

<div class="post-metadata">

**Author:** ![pirxthepilot](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/pirxthepilot/32/4106_2.png) [@pirxthepilot](https://discuss.dgraph.io/u/pirxthepilot)\
**Post date:** [May 27, 2020, 7:50pm UTC](https://discuss.dgraph.io/t/querying-and-visualization-with-jupyter-notebook/6834/3 "2020-05-27T19:50:22Z")

</div>

@Anurag thanks for the welcome!

I am using Ratel and it’s pretty great, but we also work with other data that’s not in DGraph and would like to consolidate everything in one place (Jupyter). Do you think the pygraphistry method can be one way to do this?

This will be used primarily in analyzing log events in a security context. As for data size, I’m not sure yet, we are still playing around with it 🙂

---

<div class="post-metadata">

**Author:** ![Anurag](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/anurag/32/2599_2.png) [@Anurag](https://discuss.dgraph.io/u/Anurag)\
**Post date:** [May 28, 2020, 4:11pm UTC](https://discuss.dgraph.io/t/querying-and-visualization-with-jupyter-notebook/6834/4 "2020-05-28T16:11:57Z")

</div>

Hey @pirxthepilot,  
We haven’t seen anyone use pygraphistry with Dgraph but you are encouraged to try. I feel you can use any visualization tool once you have the JSON data from dgraph. We have seen people use [d3](https://medium.com/@stallonejacob/d3-in-juypter-notebook-685d6dca75c8) with Dgraph maybe you could explore that as well.

---

<div class="post-metadata">

**Author:** ![pirxthepilot](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/pirxthepilot/32/4106_2.png) [@pirxthepilot](https://discuss.dgraph.io/u/pirxthepilot)\
**Post date:** [May 28, 2020, 9:19pm UTC](https://discuss.dgraph.io/t/querying-and-visualization-with-jupyter-notebook/6834/5 "2020-05-28T21:19:22Z")

</div>

Oh nice, d3 looks very promising! Will check it out, thank you!

---

<div class="post-metadata">

**Author:** ![lmeyerov](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/lmeyerov/32/8655_2.png) [@lmeyerov](https://discuss.dgraph.io/u/lmeyerov)\
**Post date:** [July 30, 2021, 6:31pm UTC](https://discuss.dgraph.io/t/querying-and-visualization-with-jupyter-notebook/6834/6 "2021-07-30T18:31:17Z")

</div>

@pirxthepilot@Anurag Just saw this when another dgraph user asked the same thing:

With just a few lines, you should be be able to do something like:

```auto
import json, pandas as pd, pydgraph, graphistry

# #### 1. Dgraph data wrangling ###

txn = pydgraph.DgraphClient(...).txn()
dql_query = """
my query
"""
dql_opts = { }
edges_df = pd.DataFrame(json.loads(txn.query(dql_query, dql_opts).json))
print(edges_df.info())
print(edges_df.sample(10))

# #### Plotting 1-liners ####

g1 = graphistry.edges(edges_df, 'some_src_col', 'some_dst_col')
g1.plot()

nodes_df = # same flow as for dql -> edges_df
g2 = g1.nodes(nodes_df, 'some_node_id_col') # new plottable that layers on node bindings
g2.plot()

url = g2.plot(render=False) # now as a url for, say, manual iframe'ing in an app or pasting into Slack

```

It’d be great to get a sample notebook into the dgraph + pygraphistry docs, esp. now that we have the free Graphistry Hub tier out. This should save folks time from having to the more awkward & manual graph libs, bring in the ability to use pydata flows, enable them to see much more of their data + visually interact with it.

Also worth noting, for folks not using the dgraph python client, all of the above is just thin wrappers over Graphistry’s REST web API (and optional JS client one): [https://hub.graphistry.com/docs](https://hub.graphistry.com/docs)

---

<div class="post-metadata">

**Author:** ![matthewmcneely](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/matthewmcneely/32/4774_2.png) [@matthewmcneely](https://discuss.dgraph.io/u/matthewmcneely)\
**Post date:** [June 27, 2023, 5:53pm UTC](https://discuss.dgraph.io/t/querying-and-visualization-with-jupyter-notebook/6834/7 "2023-06-27T17:53:45Z")

</div>

For those following this thread, see: [Jupyter Notebook with graph visualization (via Graphistry) now available](http://discuss.hypermode.com/t/jupyter-notebook-with-graph-visualization-via-graphistry-now-available/18755)
