- Notifications
You must be signed in to change notification settings - Fork47
A simple Python data-structure visualization tool for lists of lists, lists, dictionaries; primarily for use in Jupyter notebooks / presentations
License
parrt/lolviz
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
ByTerence Parr. SeeExplained.ai for more stuff.
A very nice lookingjavascript lolviz port with improvements byAdnan M.Sagar.
A simple Python data-structure visualization tool that started out as aListOfLists (lol) visualizer but now handles arbitrary object graphs, including function call stacks! lolviz tries to look out for and format nicely common data structures such as lists, dictionaries, linked lists, and binary trees. This package is primarily for use in teaching and presentations with Jupyter notebooks, but could also be used for debugging data structures. Useful for devoting machine learning data structures, such as decision trees, as well.
It seems that I'm always trying to describe how data is laid out in memory to students. There are really great data structure visualization tools but I wanted something I could use directly via Python in Jupyter notebooks.
The look and idea was inspired by the awesomePython tutor. The graphviz/dot tool does all of the heavy lifting underneath for layout; my contribution is primarily making graphviz display objects in a nice way.
There are currently a number of functions of interest that returngraphviz.files.Source
objects:
listviz()
: Horizontal list visualizationlolviz()
: List of lists visualization with the first list vertical and the nested lists horizontal.treeviz()
: Binary trees visualized top-down ala computer science.objviz()
: Generic object graph visualization that knows how to find lists of lists (likelolviz()
) and linked lists. Trees are also displayed reasonably, but with left to right orientation instead of top-down (a limitation of graphviz). Here is an example linked list and dictionary:callsviz()
: Visualize the call stack and anything pointed to by globals, locals, or parameters. You can limit the variables displayed by passing in a list ofvarnames
as an argument.callviz()
: Same ascallsviz()
but displays only the current function's frame or you can pass in a Python stack frame object to display.matrixviz(data)
: Display numpyndarray
; only 1D and 2D at moment.strviz()
: Show a string like an array.
Given the return value in generic Python, simply call methodview()
on the returned object to display the visualization. From jupyter, call functionIPython.display.display()
with the returned object as an argument. Function arguments are in italics.
Check out theexamples.
First you need graphviz (more specifically thedot
executable). On a mac it's easy:
$ brew install graphviz
Then just install thelolviz
Python package:
$ pip install lolviz
or upgrade to the latest version:
$ pip install -U lolviz
From within generic Python, you can get a window to pop up using theview()
method:
fromlolvizimport*data= ['hi','mom',{3,4},{"parrt":"user"}]g=listviz(data)print(g.source)# if you want to see the graphviz sourceg.view()# render and show graphviz.files.Source object
From within Jupyter notebooks you can avoid therender()
call because Jupyter knows how to displaygraphviz.files.Source
objects:
For more examples that you can cut-and-paste, please see the jupyter notebook full ofexamples.
There are global preferences you can set that affect the display for long values:
prefs.max_str_len
(Default 20). How many chars in a string representation of a value before we abbreviate with...
. E.g.,:prefs.max_horiz_array_len
(Default 70) Lists can quickly become too wide and distort the visualization. This preference lets you set how long the combined string representations of the list values can get before we use a vertical representation of the list. E.g.,:prefs.max_list_elems
. Horizontal and vertical lists and sets show maximum of 10 (default) elements.prefs.float_precision
. How many decimal places to show for floats (default is 5).
Mostly notes for parrt to remember things.
Ugh.
shape=record
means html-labels can't use ports. warning!warning:
<td>
and</td>
must be on same line or row is super wide!
$ python setup.py sdist upload
Or to install locally
$cd~/github/lolviz$ pip install.
About
A simple Python data-structure visualization tool for lists of lists, lists, dictionaries; primarily for use in Jupyter notebooks / presentations