How to draw oriented edges on PyVis
Asked Answered
M

1

6

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?

Merit answered 2/12, 2021 at 8:23 Comment(0)
A
11

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

Armenta answered 2/12, 2021 at 11:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.