---
# System prepended metadata

title: Visualisation

---

# Visualisation

```python=
from pyvis.network import Network

def graph_around_node(sdg_g,nids,radius=10):
    try:
        nodes=set([abs(x) for x in nids])
    except:
        nodes=set([abs(nids)])
    to_explore=set(nodes)
    for step in range(radius):
        new_to_explore=set()
        for nid in to_explore:
            nv=sdg_g.get_nodeview(nid)
            for nnid in [l.node().node_id() for l in nv.next()+nv.prev()]:
                if abs(nnid) not in nodes:
                    new_to_explore.add(abs(nnid))
                    nodes.add(abs(nnid))
        to_explore=new_to_explore
    
    g = Network(height=1000,width=1500,notebook=True)
    #g.force_atlas_2based()
    g.hrepulsion()
    for nid in nodes:
        g.add_node(f'{nid}+',color='gray',label="+")
        g.add_node(f'{nid}-',color='gray',label="-")
        g.add_edge(f'{nid}+',f'{nid}-',color='gray',width=10,label=f'{nid}',smooth=False)#,physics=False,length=100)#,weight=50)
    #connections=set()
    for nid in nodes:
        nv=sdg_g.get_nodeview(nid)
        for l in nv.next():
            onid=l.node().node_id()
            if abs(onid) not in nodes or abs(onid)<nid: continue
            if onid>0: g.add_edge(f'{nid}-',f'{onid}+',color='gray')
            else: g.add_edge(f'{nid}-',f'{-onid}-',color='gray')
        for l in nv.prev():
            onid=l.node().node_id()
            if abs(onid) not in nodes or abs(onid)<nid: continue
            if onid>0: g.add_edge(f'{nid}+',f'{onid}-',color='gray')
            else: g.add_edge(f'{nid}+',f'{-onid}+',color='gray')
    g.set_options('''
        var options = {
          "nodes": {
            "size": 10
          },
          "edges": {
            "smooth": {
              "type": "continuous",
              "forceDirection": "none"
            }
          },
          "physics": {
            "hierarchicalRepulsion": {
              "centralGravity": 0,
              "springLength": 50,
              "nodeDistance": 150
            },
            "maxVelocity": 150,
            "minVelocity": 0,
            "solver": "hierarchicalRepulsion",
            "timestep": 0.9
          }
        }''')
    return g.show("basic.html")
```

![](https://i.imgur.com/cRvHG51.png)
