I have been struggling with a simple question. How to change the label size for a certain type of node? My nodes are switches and their ports. I wish to have nodes that are switches to have their labels in a larger size font than the port nodes. I am using networkx and pyvis to plot my data.
I essentially want when I add nodes (lsysname, rsysname, lswname) to have a larger font size e.g. 25. I want when I add ports as nodes for the font size to be the default 12. Is this at all possible? If yes how would I alter my code below?
Here is my code:
#!/usr/bin/env python3
import pandas as pd
from pyvis.network import Network
import networkx as nx
import re
nt = nx.Graph()
nt = Network(height='750px', bgcolor='#222222')
# set the physics layout of the network
nt.barnes_hut(gravity=-80000, central_gravity=0.3, spring_length=10, spring_strength=0.002, damping=0.09, overlap=0)
got_dataLLDP = pd.read_csv('switchLLDPgraph.csv', sep='|')
got_dataPortDescr = pd.read_csv('switchPortDescr.csv', sep='|')
#lsystemname and rsystemname are SWITCHES
#lportnode and rportnode are PORTS
lsystemname = got_dataLLDP['Local SystemName']
lsystemdescr = got_dataLLDP['Local SystemDescr']
lportnode = got_dataLLDP['Local PortNode']
lportlabel = got_dataLLDP['Local PortLabel']
rsystemname = got_dataLLDP['Remote SystemName']
rsystemdescr = got_dataLLDP['Remote SystemDescr']
rportnode = got_dataLLDP['Remote PortNode']
rportlabel = got_dataLLDP['Remote PortLabel']
#lswitchname are SWITCHES
#lswitchport are PORTS
lswitchname = got_dataPortDescr['SW Name']
lswitchport = got_dataPortDescr['Local PortNode']
lswitchportstate = got_dataPortDescr['PORT STATE']
edge_dataLLDP = zip(lsystemname, lsystemdescr, lportnode, lportlabel, rsystemname, rsystemdescr, rportnode, rportlabel)
edge_dataPortDescr = zip(lswitchname, lswitchport, lswitchportstate)
for e in edge_dataLLDP:
lsysname = e[0]
lpnode = e[2]
lplabel = e[3]
rsysname = e[4]
rpnode = e[6]
rplabel = e[7]
nt.add_node(lsysname, lsysname, size=100, shape='triangle', color='#1abc9c')
nt.add_node(lpnode, lplabel, size=25, color='#DFFF00')
nt.add_node(rsysname, rsysname, size=100, shape='triangle', color='#1abc9c')
nt.add_node(rpnode, rplabel, size=25, color='#DFFF00')
nt.add_edge(lsysname, lpnode, value=0.05, color='#DFFF00')
nt.add_edge(lpnode, rpnode, value=0.03, color='#FFFFCC')
nt.add_edge(rsysname, rpnode, value=0.05, color='#DFFF00')
for f in edge_dataPortDescr:
lswname = f[0]
lswport = f[1]
lswportstate = f[2]
pattern = '\!Description'
result = re.search(pattern, lswport)
nt.add_node(lswname, lswname, size=100, shape='triangle', color='#1abc9c')
if lswportstate == 'Up':
if result:
nt.add_node(lswport, lswport, size=25, color='#EA580C')
nt.add_edge(lswname, lswport, value=0.035, color='#EA580C')
else:
nt.add_node(lswport, lswport, size=25, color='#00FF00')
nt.add_edge(lswname, lswport, value=0.035, color='#00FF00')
if lswportstate == 'Down':
if result:
nt.add_node(lswport, lswport, size=25, color='#EA580C')
nt.add_edge(lswname, lswport, value=0.035, color='#FF0000')
else:
nt.add_node(lswport, lswport, size=25, color='#FF0000')
nt.add_edge(lswname, lswport, value=0.035, color='#FF0000')
nt.show_buttons()
nt.show('nx.html')