pyvis.network shows html which is not 100 percent of the page

148 views Asked by At

with this simple code the output is as expected but only in a 30% of the browser window.

import networkx as nx
from pyvis.network import Network

G = nx.Graph()
G.add_node(1)
G.add_node(2)
G.add_node(3)

G.add_edge(1, 2)
G.add_edge(1, 3)

net = Network(height="100%", width="100%", directed=True, notebook=True)
net.from_nx(G)
net.show("simple.html")

is there a better parameter to use realy 100% of the browser ?

or is there a better library to actully achiev something like that with python ?

enter image description here

1

There are 1 answers

0
Ali Ent On BEST ANSWER

The reason why you cannot change the canvas size when you set it on 100% is that it is not 100% of browser window, it's 100% of its parent's height.

If you change width and background color, you see the canvas is inside another frame.

net = Network(height="500px", width="500px", directed=True, notebook=True, bgcolor="#ff0000")

enter image description here

You just need to give its size in pixel, and it will change its parent's size too.

net = Network(height="600px", width="100%", directed=True, notebook=True)

enter image description here