I am trying to visualize some quantitative data that can be summarized hierarchically. The data is arranged such that each node either:
- has children, with this node's value the mean of the value of its children
- has no children (is terminal) with a set value
For example:
A = mean(AA, AB) = mean(0.75 + 0.85) = 0.8
AA = mean(AAA, AAB) = mean(0.6 + 0.9) = 0.75
AAA = 0.6
AAB = 0.9
AB = 0.85
My current plan is a figure like the following:
Where node A is centered above the figure that shows its children, AD is centered above the subplot showing its children, etc...
My current solution is to approach it recursively using matplotlib and gridspec (traverse down the hierarchy, splitting the plot area using gridspec into a top row and the rest, then recursing on the columns in the row below). It "works", but there's a lot of little cases I have to handle, such as:
- making sure the leftmost figure has y-axis labels, which is awkward in cases like the bottom where the second column needs to know it is the leftmost real figure
- making sure figures like the CA-CB-CC figure which terminate before the bottom row don't extend beyond their row
- handling the vertical padding between plots such that long labels can be rotated 45deg without overlap
- when using gridspec the subplots are not always vertically aligned (some are a bit taller or shorter than others)
To catch these I have to pass a lot of state around and fix edge cases. Are there any other plotting libraries or a different approach with matplotlib that might work better?
EDIT:
Adding a colored figure with the pattern of the recursion in my current attempt.
* first (top level) call partitions everything by the green boxes (2 rows, with the bottom row split into 3 col) then recursively plots the three columns independently
* second call (yellow) splits the bottom left into two rows, recursing on its child columns
* third call (orange) ...
* fourth call (red) ...
The downside to this is I don't think I can easily do a shared y-axis across a given row because they're isolated from their neighbors. The only caller that has that context is the top level, so I'd have to reach down into all the plots afterwards and link their y-axes.