<jupyter_start><jupyter_text>Using networkx to create a hierarchical graphsnetworkx: __[networkx.github.io](https://networkx.github.io/documentation/stable/index.html)__<jupyter_code>import networkx as nx
import re
from pathlib import Path
import matplotlib.pyplot as plt
from pprint import pprint
%matplotlib inline
G = nx.DiGraph()
base_node = 'A'
sub_nodes = [f'A{d}' for d in range(3)]
final_node = 'B'

G.add_nodes_from([base_node, *sub_nodes, final_node])
G.add_edges_from([(base_node, n) for n in sub_nodes])
G.add_edges_from([(n, final_node) for n in sub_nodes])

pprint(nx.convert.to_dict_of_dicts(G))
pprint(nx.convert.to_dict_of_lists(G))<jupyter_output>{'A': {'A0': {}, 'A1': {}, 'A2': {}},
 'A0': {'B': {}},
 'A1': {'B': {}},
 'A2': {'B': {}},
 'B': {}}
{'A': ['A0', 'A1', 'A2'], 'A0': ['B'], 'A1': ['B'], 'A2': ['B'], 'B': []}<jupyter_text>**REM**: for ```nx.drawing.nx_agraph.graphviz_layout``` one needs to install pygraphviz```pip install pygraphviz```(It might be necessery to to install graphviz first: ```apt-get install graphviz```)How to plot a hierarchichal plot is explained in__[stackoverflow.com/a/11484144/5172579](https://stackoverflow.com/a/11484144/5172579)__<jupyter_code>pos =nx.drawing.nx_agraph.graphviz_layout(G, prog='dot')
g = nx.draw(G, pos, with_labels=True, font_weight='bold')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.19524870081662954, 'fraction_numerical': 0.03192279138827023, 'mean_word_length': 7.023809523809524, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '379076', 'license': '0BSD', 'n_tokens_mistral': 567, 'n_tokens_neox': 540, 'n_words': 113, 'path': 'eye_candy/graphs_networkx/networkx_parallel.ipynb', 'repo_name': 'flokno/python_recipes', 'size': '1347'}