Python graph like windirstat? - python

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.

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.

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.

Related

How to go from STEP geometry to CSG

I am trying to transform a solid created in a CAD program (saved in a STEP file) into a CSG object constructed with simple primitives.
I am not very familiar with the different geometry file formats but as far as I understand it should be possible to do, at least with some simple solids, since the information about the face shapes etc. is stored in a STEP file. I have found this issue https://github.com/tpaviot/pythonocc-core/issues/470 which proves you can extract some of this information. However I am not sure this is enough to achieve my goal.
As an example, I would like to go from the following CAD design / STEP file:
to a CSG description which should describe the geometry as a big cylinder with three smaller cylinders as subtractions.
Ideally I would use a python library for this purpose, perhaps this library is a good candidate.
However I am afraid this isn't theoretically possible since I am not finding much information online.
As a last resort I could just mesh the solid and generate a CSG description using a tessellated solid, but I want to use simple primitives such as boxes or cylinders whenever possible.
I would love to know if this is possible to do and if so, I would love some resources to read about this. Thanks!

Networkx Programatic Network Graph Visualization

Hopefully this question isn't too opinion based. If it is, can you point me in the right direction for this question.
I am hoping to create something simple to visualize a twitter network that has been defined with networkx. What are the best available visualization tools for this? I would like to have something along the lines of, I run a script and get display a png or some image of the network that isn't too cluttered. I would definitely like to differentiate between usernames and hashtags and possibly color by community or something along those lines.
I haven't started anything yet other than playing with the built in networkx drawing which is limited and networkx doesn't even recommend. The tools I've found in my search include plot.ly, gephi, d3.js, and cytoscape. Plot.ly is proprietary so I'd like to stay away from it. D3.js seems pretty cool. I plan on using it eventually for some interactive graphs, but I hear there are performance issues and limitations to hundreds of nodes vs thousands of nodes. Also I'm not familiar with javascript at all. Gephi and cytoscape aren't really programmatic. They are nice, but require a human element.
Does anything already exist that meets my needs? Is the human element required to get decent looking output? I can get okay results with the built in networkx drawing, but it requires significant tweaking for each case (remove overlapping, setting up a half decent layout, etc...). Also the fact that networkx mentions they may drop support for drawing in the future doesn't help.
No need to use Javascrip. Bokeh is a Python library for D3.
You can also consider NodeBox if on OSX or NetworkX Viewer, but probably what you are looking for is Graph-Tool.

Using Python to output a category-based graph

I'm looking to create a survey program in Python that outputs the results of a series of questions into a few broad categories. As an example, I'm looking for something specifically along the lines of:
The idea is that the survey will give you a score between 3 and -3 and you lean towards one category or the other, depending on whether you scored positively or negatively.
Now, my idea is to manually use PIL to:
Iterate through appropriate category names and draw them
Draw the associated lines
Draw the rectangles according to score.
Also, it's worth mentioning that I'm trying to keep this as flexible as possible; we might add or remove categories at a later stage and I'd like to keep it so it would take minimal programming effort to do (as I likely will not be the one maintaining this in the future).
I suppose what my question would be is... does anyone know of any packages that might do this nicely? Or perhaps have any other suggestions or ideas? I didn't see anything suitable off of matplotlib. Admittedly, however, my expertise in graphing with Python is not extensive by any means!
Thanks for any ideas you might have!

Python: create SVG

What I want is to create some electrical symbols (transistor, capacitor, diode...) and than to use them like a puzzle elements to create electrical scheme drawing and save it as one SVG file.
My idea is
Use some kind of scheme for SVG (like XML Scheme) to create complex electrical symbols out of basic shapes: lines, circles, square...
Use instances of those symbols, with coordinates (which I load in Python) to put them in the right place in final electrical scheme
Save it as .SVG
What is the best way to do that? (SVGFig looks like it would do it, but I can't find similar examples)
Examples would be appreciated.
Hm, not sure if it helps you, but there was a program, called Dia diagram editor, meant for drawing SVGs and equipped with Python command line. It's quite glitchy, though, but at least it has a good set of electrical symbols within and works with SVG. Good luck!
Here are some examples:
https://mail.gnome.org/archives/dia-list/2010-August/msg00014.html
https://live.gnome.org/Dia/Python

How to use R-Tree for plotting large number of map markers on google maps

After searching SO and multiple articles I haven't found a solution to my problem.
What I am trying to achieve is to load 20,000 markers on Google Maps.
R-Tree seems like a good approach but it's only helpful when searching for points within the visible part of the map. When the map is zoomed out it will return all of the points and...crash the browser.
There is also the problem with dragging the map and at the end of dragging re-running the query.
I would like to know how I can use R-Tree and be able to achieve the all of the above.
As noted, R-Tree won't help you when you're looking at a zoomed-out view. This problem is often addressed by marker clustering, because showing 20,000 points in a browser window isn't that useful.
Marker Manager is an open source javascript library which addresses this, but there are others.
With a very great number of markers, you may need to look at server-side clustering, (where R-Tree may come in handy!). Here is one discussion of it, and its google cache because link is dead at time of writing.
If you don't want to bother with clustering, then just terminate your marker list at a preset number, maybe a few hundred (which you can determine by usability testing), and display some indication that there are more available as you zoom in

Categories