0

I would like to make a graphical visualization of a nested dictionary as a simple tree structure. I have tried several different solutions, but they are too old (python 2.7) or I get weird error messages, even after reinstalling the packages needed.

Here is an example of the nested dictionary. I can change the end nodes value to be whatever value is most useful and the dictionary should be able to scale and be used on a way bigger file structure.

{
    "Folder1": {},
    "Folder2": {
        "Folder21": {},
        "Folder22": {}
    },
    "Document1": {},
    "Document2": {},
    "Folder3": {
        "Document31": {},
        "Folder32": {
            "Document 321": {},
            "Document 322": {}
        },
        "Folder33": {
            "Document331": {}
        },
        "Folder34": {
            "Document341": {}
        }
    }
}

I have tried solutions using Mapping, NetworkX, GraphViz, pandas, matplotlib 3.1.3, Json, d3py 0.2.3, pyplot, numpy 1.18.1 and Pydot (pydot2 1.0.33, pydotplus 2.0.2). Using pip3 18.1 to install the packages in Ubuntu 19

Then goal is creating something like this post has, but it is 7 years old, and I can't get it to work after translating from Python2 to Python3. Python library for creating tree graphs out of nested Python objects (dicts)

AdrianP
  • 13
  • 4
  • Did you read *"note: d3 renders in the browser; the image above is just a screen shot of my browser window"*? d3.js is still the very recommended package for this type of renderings. You just need to copy some very short javascript code. Google for "d3js tree layout" to find the layout that best suits your needs. There are millions of variations possible. – JohanC Mar 24 '20 at 12:33
  • Yeah, I saw that but couldn't figure out how to render it from Python. Could you give me a hint on how to render the Json.dumps data in my browser? – AdrianP Mar 24 '20 at 13:33
  • For example [here](https://observablehq.com/@d3/collapsible-tree) it just does `data = FileAttachment("flare-2.json").json()`. At the top of the page is a "..." menu to download the code as a selfrunning example. Just unpack it in a fresh directory and open the index.html. – JohanC Mar 24 '20 at 13:47
  • If you look for a solution in python you can check [Tree plotting in python](https://stackoverflow.com/questions/7670280/tree-plotting-in-python) – Sparky05 Mar 24 '20 at 17:45

0 Answers0