Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pyvis: how do I add a title/heading to the graph animation

I am using Pyvis to visualize big network graphs. I would like to generate graphs with certain headings and then save them as jpg or png images. However, I don't see any such option in the documentation. There is a heading parameter for the class Network, but it generates a heading for the HTML file and not for the interactive element of the graph.

from pyvis import network as net
from IPython.core.display import display, HTML
g=net.Network(height='400px', width='50%',heading='Graph')
g.add_node(1)
g.add_node(2)
g.add_node(3)
g.add_edge(1,2)
g.add_edge(2,3)
g.show('example.html')
display(HTML('example.html'))

generates this graph that I have screenshot below. enter image description here

How can I change the Graph heading to be in the box containing the graph, and can I saw this as a png or jpg image?

like image 367
winawer Avatar asked Nov 18 '25 12:11

winawer


1 Answers

I think this i not possible with pyvis since the network object cant not contain text. But you can add headlines or text directly above and below your graph by adding a headline and/or paragrah element to your html document.

<body>
    <div class="card" style="width: 100%">
        <h1>headline above div with id = "mynetwork"</h1>
        <p>text above div with id = "mynetwork"</p>
        <div id="mynetwork" class="card-body"></div>
        <p>text below div with id = "mynetwork"</p>
    </div>
    ...
</body

The headline and text will appear like this

like image 62
Rullkali Avatar answered Nov 21 '25 00:11

Rullkali