2

I have a text corpus for which I want to visualize the co-occurence of words as a network. To do so, I have created a pd Dataframe cooc_pd with the columns Source,Target and Weight. The first two are nodes and Weight indicates how often the two nodes (words) occur within a set window_size.

Then, I use the following code to plot a network:

import networkx as nx
from pyvis.network import Network
import pandas as pd

G = nx.from_pandas_edgelist(cooc_pd, 
                            source = 'Source', 
                            target = 'Target',
                            edge_attr='Weight')

net = Network(notebook=True)
net.from_nx(G)
net.show("example.html")
 

If I choose a low threshold for weight inclusion, many connections are shown in the graph. However, in that case the nodes in the example.html are constantly moving and interpretation is difficult. Is there a way (other then increasing the threshold) to make the nodes stop moving?

Yannis P.
  • 2,745
  • 1
  • 24
  • 39
Emil
  • 1,531
  • 3
  • 22
  • 47
  • PyVis is a rather new package that looks very exciting. I had, personally, not heard of it before, but I am just wondering if the constant movement, has something to do with a layout algorithm, keep being executed. Have you checked the parameters for [Physics](https://pyvis.readthedocs.io/en/latest/tutorial.html#using-the-configuration-ui-to-dynamically-tweak-network-settings), perhaps trying to totally deactivate. – Yannis P. Jun 24 '21 at 15:36

2 Answers2

8

I was having the same problem with my graph, it kept moving in a noisy way.

Reading the documentation, I've found a method called repulsion, which "Set the physics attribute of the entire network to repulsion".

Right after creating the Network, I've inserted this and it worked fine:

from pyvis.network import Network

net = Network()
net.repulsion()
senajoaop
  • 196
  • 2
  • 3
2

You can use

G.show_buttons(filter_=['physics']) 

to manage physical parameters using sliders in the visualization.

XavierStuvw
  • 1,294
  • 2
  • 15
  • 30
Sara
  • 33
  • 4