使用 networkx 在 matplotlib 中显示节点的基本程序

import networkx as nx  # importing networkx package
import matplotlib.pyplot as plt # importing matplotlib package and pyplot is for displaying the graph on canvas 
b=nx.Graph()
b.add_node('helloworld')
b.add_node(1)
b.add_node(2)
'''Node can be called by any python-hashable obj like string,number etc'''
nx.draw(b)  #draws the networkx graph containing nodes which are declared till before
plt.show()  # displays the networkx graph on matplotlib canvas

补充说明:

nx.draw(b,nodelist=[1,'helloworld']) #displays the particular nodes which are given by nodelist only 
nx.draw_networkx(b,nodelist=[1,'helloworld']) #displays the node along with its name given by us i.e 1, hello  respectively