Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

** Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement! **

Add Node into a Graph

<networkx.classes.graph.Graph at 0x7f060b4b3700>
NodeView((1, 2))
{1, 2}
True
True
{}
{'x': 100}
{'x': 100}

A node is a hashable object while the attributes of a node is a dict.

dict

Existing nodes and attributes are reused when adding nodes into a graph.

NodeView((1, 'Hello'))
{'x': 10, 'y': 20}
NodeView((1, 'Hello', ('http://github.com/dclong/xinstall', 'master')))
{}

Add Edge into a Graph

Adding an edge into a graph automatically add the nodes of the edge into the graph.

<networkx.classes.graph.Graph at 0x1397f0670>
NodeView((1, 2))
EdgeView([(1, 2)])
{}

Existing node is reused when creating an edge.

<networkx.classes.graph.Graph at 0x1397f0220>
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-1-666954a34ddf> in <module>
----> 1 graph.nodes

NameError: name 'graph' is not defined
{'x': 10}

DiGraph

<networkx.classes.digraph.DiGraph at 0x131afd7c0>

Get Predecessors/Parents

[1, 3]

Get Successors/Children

[2]

Visualization

[('a', 'b'), ('c', 'e'), ('c', 'f')]
[('a', 'c'), ('a', 'd'), ('c', 'd')]
<Figure size 576x432 with 1 Axes>
{'a': array([-0.52190174, 0.09425555]), 'b': array([-1. , 0.32564189]), 'c': array([ 0.40979282, -0.01115702]), 'd': array([-0.39569899, -0.45872164]), 'e': array([0.75723908, 0.36174601]), 'f': array([ 0.75056884, -0.31176479])}
<Figure size 432x288 with 1 Axes>
<Figure size 432x288 with 1 Axes>
<Figure size 432x288 with 1 Axes>
{'a': Text(-0.5219017365690998, 0.09425554685676928, 'a'), 'b': Text(-1.0, 0.32564189274221367, 'b'), 'c': Text(0.4097928153942144, -0.01115702318855791, 'c'), 'd': Text(-0.3956989937868261, -0.4587216373044083, 'd'), 'e': Text(0.757239076476884, 0.3617460091278071, 'e'), 'f': Text(0.7505688384848274, -0.3117647882338241, 'f')}
<Figure size 432x288 with 1 Axes>
<Figure size 432x288 with 1 Axes>
<Figure size 576x432 with 1 Axes>