Add existing project files
This commit is contained in:
parent
432b0ec10f
commit
1f02b8d265
7 changed files with 263 additions and 0 deletions
68
lib/graph.py
Normal file
68
lib/graph.py
Normal file
|
@ -0,0 +1,68 @@
|
|||
|
||||
from networkx import from_pandas_edgelist
|
||||
from pandas import DataFrame
|
||||
from pyvis.network import Network
|
||||
|
||||
def pyvis_graph_from_pandas_DF(pandas_df:DataFrame, source_column:str="link1", target_column:str="link2", heading:str=None) -> Network:
|
||||
|
||||
nx = from_pandas_edgelist(pandas_df, source=source_column, target=target_column)
|
||||
pyvis_net = Network(bgcolor="#222222", font_color="#fafafa", width="100%", height="95%")
|
||||
pyvis_net.from_nx(nx, default_node_size=8)
|
||||
|
||||
if heading != None:
|
||||
pyvis_net.heading = heading + """
|
||||
<style>
|
||||
body {
|
||||
background-color: #222222;
|
||||
}
|
||||
h1 {
|
||||
font-size: 1.15rem;
|
||||
margin: .5rem;
|
||||
color: #fafafa;
|
||||
font-family: sans-serif;
|
||||
}
|
||||
#mynetwork {
|
||||
border: none !important;
|
||||
}
|
||||
</style>
|
||||
"""
|
||||
|
||||
pyvis_options = """
|
||||
var options = {
|
||||
"nodes": {
|
||||
"font": {
|
||||
"size": 12
|
||||
}
|
||||
},
|
||||
"edges": {
|
||||
"arrows": {
|
||||
"to": {
|
||||
"enabled": true,
|
||||
"scaleFactor": 0.3
|
||||
}
|
||||
},
|
||||
"color": {
|
||||
"inherit": true
|
||||
},
|
||||
"smooth": false
|
||||
},
|
||||
"interaction": {
|
||||
"hover": false
|
||||
},
|
||||
"physics": {
|
||||
"barnesHut": {
|
||||
"centralGravity": 0,
|
||||
"springLength": 200,
|
||||
"springConstant": 0.01,
|
||||
"avoidOverlap": 0
|
||||
},
|
||||
"minVelocity": 0.75
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
# pyvis_net.show_buttons()
|
||||
pyvis_net.set_options(pyvis_options)
|
||||
|
||||
return pyvis_net
|
||||
|
Reference in a new issue