pyvis icon indicating copy to clipboard operation
pyvis copied to clipboard

Graphs display with bowing or curving edges in Jupyter Notebook

Open LelandBarnard opened this issue 2 years ago • 1 comments

Following a recent update, whenever I display a graph in a jupyter notebook now the edges are displayed as bowed or curved lines, rather than straight lines as they used to. Here is a test example:

import pyvis.network
import networkx
g = pyvis.network.Network(notebook = True, bgcolor = 'black', font_color = 'white', height="600px", width="90%", cdn_resources='remote')
nxg = nx.complete_graph(8)
g.from_nx(nxg)
display(g.show('test_case.html'))

which produces this output: image

How can I get it to display with straight edges as it used to?

LelandBarnard avatar Mar 09 '23 23:03 LelandBarnard

Hey! Maybe a bit late but I found that this line: https://github.com/WestHealth/pyvis/blame/ccb7ce745ee4159ce45eac70b9848ab965fc0906/pyvis/options.py#L58

Was the only line changed in years. So basically the smoothing was always enabled (compared to before) without a recommended or documented way to toggle the smoothness. The only solution I found was to just set smoothing off manually:

from pyvis.network import Network

network = Network()
network.options.edges.smooth.enabled = False

This will result in your network graph to be displayed with straight edges.

Your code:

import pyvis.network
import networkx as nx
from IPython.display import display, HTML

g = pyvis.network.Network(notebook = True, bgcolor = 'black', font_color = 'white', height="600px", width="90%", cdn_resources='remote')
g.options.edges.smooth.enabled = False
nxg = nx.complete_graph(8)
g.from_nx(nxg)
display(HTML(g.generate_html()))

image

Laminator42 avatar Jun 01 '23 12:06 Laminator42