This is my first experience visualizing from hierarchical data in dictionary format using Python. The last piece of data is as follows:
d = {^2820: [^391, ^1024], ^2821: [^759, 'w', ^118, ^51], ^2822: [^291, 'o'], ^2823: [^25, ^64], ^2824: [^177, ^2459], ^2825: [^338, ^1946], ^2826: [^186, ^1511], ^2827: [^162, 'i']}
So, I have indexes in lists referring to keys (index) of the dictionary. I suppose this could be used as a basic structure for visualization, please correct me if I am wrong. Data symbols are βleaf nodes / leavesβ that do not refer to any index.
I found NetworkX, which, perhaps, could be used for visualization, but I have no idea where to start with it and my data. I was hoping it would be so simple:
import networkx as nx import matplotlib.pyplot as plt d = {^2820: [^391, ^1024], ^2821: [^759, 'w', ^118, ^51], ^2822: [^291, 'o'], ^2823: [^25, ^64], ^2824: [^177, ^2459], ^2825: [^338, ^1946], ^2826: [^186, ^1511], ^2827: [^162, 'i']} G = nx.Graph(d) nx.draw(G) plt.show()
I am looking for a hierarchical dendrogram or some kind of clustering as output. Sorry, at the moment I'm not quite sure what would be the best visualization, maybe it looks like this:

UPDATE
Using NetworkX was actually very simple. I provide other simple data examples and look for an answer if it can be visualized with a dendrogram instead of a wired network diagram as well?
# original sequence: a,b,c,d,b,c,a,b,c,d,b,c d = {^1: ['b', 'c'], ^2: ['a', ^1, 'd', ^1], 'S': [^2, ^2]} G = nx.Graph(d) nx.draw_spring(G, node_size=300, with_labels=True)

As we can see, the graph shows a simple relationship, but not the hierarchy and order of the data that I am ready to do. DiGraph gives more detailed information, but it is still impossible to build the original sequence from it:

For the dendrogram, apparently, the weight and end nodes should be calculated as indicated in the first answer. For this approach, the data structure may be something like this:
d = {'a': [], 'b': [], 'c': [], 'd': [], ^1: ['b', 'c'], ^2: ['a', ^1, 'd', ^1], 'S': [^2, ^2]}