WestHealth / pyvis

Python package for creating and visualizing interactive network graphs.
http://pyvis.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
998 stars 169 forks source link

Graphs display with bowing or curving edges in Jupyter Notebook #217

Open LelandBarnard opened 1 year ago

LelandBarnard commented 1 year ago

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?

Laminator42 commented 1 year ago

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