Python 如何将属性添加到已存在的图形中

Python 如何将属性添加到已存在的图形中,python,graph,networkx,Python,Graph,Networkx,我通过将“源”、“目标”、“关系”作为数据帧传递来创建一个网络图,我想将属性添加到上述图中的一些节点,因此我将属性作为字典传递给该图,我不知道如何将属性添加到已生成的图中,因为我有多个属性,我应该使用字典 graph = nx.from_pandas_edgelist(main_df, source='Source', target='Target', edge_attr='Relationship') nx.set_node_

我通过将“源”、“目标”、“关系”作为数据帧传递来创建一个网络图,我想将属性添加到上述图中的一些节点,因此我将属性作为字典传递给该图,我不知道如何将属性添加到已生成的图中,因为我有多个属性,我应该使用字典

graph = nx.from_pandas_edgelist(main_df, source='Source', target='Target', 
                                edge_attr='Relationship')

nx.set_node_attributes(graph, node_dict)

首先,我通过传递以下参数来运行该图,然后对于该图,我传递具有属性的字典。如何将属性字典添加到“图形”?

要将一组属性添加到
图形
G:

attrs_g = {'title': 'Random graph1', 'value': 0.00}
G.graph.update(attrs_g)
要将节点属性添加到节点0和1,请执行以下操作:

attrs_n = [(0, {'name': "zero", 'elev': 10}), \
           (1, {'name': "one", 'elev': 11})]
nx.set_node_attributes(G, attrs_n)  # where nx is networkx
要将边属性添加到边(0->1),请执行以下操作:

attrs_e = [(0, 1), {'link_name': "some name", 'weight': 100}]
nx.set_edge_attributes(G, attrs_e)