Tuesday, June 28, 2022

[FIXED] How to draw oriented edges on PyVis

Issue

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?


Solution

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



Answered By - jylls
Answer Checked By - Terry (PHPFixing Volunteer)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.