Skip to content Skip to sidebar Skip to footer

I Am Trying To Open An Html File Using Python - Pyviz

I am trying to use the pyvis library to show py network using the following code: import numpy as np import networkx as nx from pyvis.network import Network adjacency_matrix = [[0

Solution 1:

Where is your HTML file? If its not in the same folder as your program, you'll have to use a direct path such as /Desktop/Your-folder/your-file

Solution 2:

If you want to display it in the same cell, use the option notebook=True (See below):

import networkx as nx
from pyvis import network as net

adjacency_matrix = [[0.5, 0.2, 0.3, 0], [0.1, 0.1, 0, 0.8], [0.3, 0, 0.4, 0.3], [0, 0.2, 0.2, 0.6]]
A = np.array(adjacency_matrix)
G = nx.from_numpy_matrix(A, create_using=nx.MultiDiGraph)
G2 = net.Network(notebook=True)
G2.from_nx(G)
G2.show('network_map.html')

Also, be sure that the notebook file (.ipynb) is in the same folder as the working directory. You can use the OS module to change directory: os.chdir(path_to_where_jupyter_notebook_is)

Post a Comment for "I Am Trying To Open An Html File Using Python - Pyviz"