0

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:

enter image description here

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) ...

None

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.

Andrew
  • 459
  • 5
  • 15
  • You don't show any code, but are you using the `ax.is_[first|last]_[row|col]` methods? – Paul H Sep 12 '19 at 23:17
  • sharing y-axes across the rows will help your vertical alignment (having code to look at would be a big help) – Paul H Sep 12 '19 at 23:18
  • Yeah sorry, it is on an air gapped computer so copy/paste wasn't an option, and it got really messy anyway. I guess I'm as much interested in if anyone has a good approach/package recommendation as specific fixes, but I'll try to add more detail tomorrow when I have it in front of me again – Andrew Sep 13 '19 at 00:02
  • I had never seen the ax.is_* methods - that would definitely be helpful. Sharing y-axis also sounds nice but I wasn't sure if I could make it work in the recursion (added figure above to describe what I mean) – Andrew Sep 13 '19 at 00:14

0 Answers0