How to draw oriented edges on PyVis

Viewed 2124

I'm trying to plot an oriented graph with pyvis. In the documentation they suggest using the following command for creating an oriented edge:

net.add_edge(4,1,from=1,to=4)

The problems are two:

  1. I'm getting this error

TypeError: add_edge() got multiple values for argument 'to'

  1. from is a python keyword so it can't be used as a parameter.

Any suggestion?

1 Answers

You don't need to directly specify to and from in your add_edge function if you had specified directed=True when you created your network. The order of the nodes in the add_edge function is enough to describe the direction. Below is an example:

from pyvis.network import Network

net = Network(directed =True)
net.add_node(0, label='a')
net.add_node(1, label='b')
net.add_edge(0,1)
net.show('mygraph.html')

And the output gives:

enter image description here

Related