9

I'm interested in using python to make diagrams representing the size of values based on the size of squares (and optionally their colour). Basically I'm looking for a way to make overviews of a bunch of values like the good old program windirstat does with hard-drive usage (it basically makes a big square representing your harddrive and then smaller squares making up the area inside of it representing different programs, the bigger the square the larger the file, colour indicates the type of file). I'm fairly familiar with matplotlib, and I don't think it's possible to do something like this with it. Is there any other python package that would help? Any suggestions for something more low level if it's not? I guess I could do it manually if I could find a way to draw the boxes programatically (I don't really care about the format, but the option to export SVG as well as PNG would be nice).

Ultimately, it would be nice to have it be interactive like windirstat is, where if you were to hover over a particular square you get more information on it, and if you clicked on it maybe you'd go in and see the makeup of that particular square. I'm only familiar with wxpython for GUI stuff, not sure if it could be used for something like this. For now I'd be happy with just outputting them though.

Thanks a lot! Alex

Edit: Thanks guys, both your answers helped a lot.

Sam
  • 1,509
  • 3
  • 19
  • 28
Alex S
  • 4,726
  • 7
  • 39
  • 67
  • 2
    "I'm fairly familiar with matplotlib, and I don't think it's possible to do something like this with it." Which would be the limitations of matplotlib ? I think it could draw sqaures of different size... – joaquin Jan 15 '12 at 18:19
  • Well I guess I'm looking for something like a Hinton diagram, which [MatPlotLib can draw](http://www.scipy.org/Cookbook/Matplotlib/HintonDiagrams), but without the spaces between the boxes. It would be more like a pie chart, but square. – Alex S Jan 15 '12 at 18:34

2 Answers2

8

You're looking for Treemapping algorithms. Once implemented, you can transform the output (which should be rectangles) into plotting commands to anything that can draw layered rectangles.

Edit:

More links and information:

If you don't mind reading papers, the browser-based d3 library provides for 'squarified' treemaps (js implementation). They reference this paper by Bruls, Huizing, and van Wijk. (This is also citation 3 on the wikipedia article)

I'd search on the algorithms listed on the linked Wikipedia article. For instance, they also link to this article, which describes an algorithm for "mixed treemaps". The paper also includes some interesting portions at the end describing transformations into other-than-rectangular shapes.

Squarified certainly appears to be the most common variety around. The above links should give you enough to work towards a solution or, even, directly port the d3 implementation. However, the cost of grokking d3's model (which is something like a declarative form of jQuery) may be somewhat high. At first glance, though, the implementation appears relatively straightforward.

twooster
  • 931
  • 7
  • 10
  • 1
    Nice, yes I think Treemapping is exactly what I'm looking for. [This list] (http://en.wikipedia.org/wiki/List_of_treemapping_software) looks to be all proprietary stuff, do you know if there are any open source options? – Alex S Jan 15 '12 at 20:10
2

Squaremap does this. I haven't used it (I only know it from RunSnakeRun) and its documentation is severely lacking, but it seems to work.

Petr Viktorin
  • 65,510
  • 9
  • 81
  • 81
  • Thanks that does look like what I'm looking for and I've downloaded it, but you're right the documentation is pretty... non-existent. – Alex S Jan 15 '12 at 20:12
  • Try deciphering RunSnakeRun source, or maybe contacting the author. It may be a lot of work, but probably not as much as writing the same thing on your own – and maybe you can even improve the situation once you understand the code. – Petr Viktorin Jan 15 '12 at 21:38