views:

326

answers:

3

I want to create a simple infographic in python. Matplotlib seems to have a lot of features but nothing that covers off my simple heatmap grid example.

The infographic is a simple 5 x 5 grid with numbers inside ranging from 0 to 1. The grid squares would then be coloured in 0=white 1=blue 0.5 being a pale blue.

Matplotlib could probably be used but I couldn't find or combine any examples that offered insight into generating this.

Any insight, example code or library direction would really help

Regards Matt

+1  A: 
Jonathan Feinberg
This is great however I'm looking to display the numbers in the grid. The coloring is secondary.
Matt Alcock
@Matt: So ... Read the above code, check out the Cairo API, and adjust it to render the text rather than a filled rectangle. How hard could that be?
unwind
I concur with unwind, the best way is to try and make sure you'd feel at ease with whatever you are going to use for your project!
RedGlyph
Good call, sounds like cario has the power I need! I'll start training up!
Matt Alcock
+3  A: 
RedGlyph
Noice. (15 chars! 15 chars!)
Jonathan Feinberg
This is great however I'm looking to display the numbers in the grid. The coloring is secondary. Also the coloring here is grandual rather than fixed for each gird square
Matt Alcock
Here you are, of course you have some flexibility in the way the grid is displayed, the format of the numbers, and so on. It would just be too long to explain here, there's a little show-off on their website: http://matplotlib.sourceforge.net/gallery.html
RedGlyph
One more comment, Jonathan's suggestion of using PyCairo could be more appropriate if you need to process images (great library by the way!). Matplotlib is more math-oriented as you might have guessed ;-) It also needs some getting used to, using IPython is a good way to try it out in a console - though not mandatory: http://ipython.scipy.org/moin/FrontPage
RedGlyph
Thanks Jonathan/Red. I'm torn between each I think I'll use the matplotlib method initally (i have that installed) and move to cario if I need to start adding in extra details (like annotations ets). Thanks to all!
Matt Alcock
I used this setting the interpolation to 'nearest' to ensure I got a heatmap feel rather than a granual effect. imshow(a, cmap=myblue, interpolation='nearest')Thanks again all!
Matt Alcock
+2  A: 
dangph
this madness... madness?? this is PYTHOOOON!!! XD
fortran
This is a hack altough it generates exactly what I was after! I don't know what my distribution mech will ultimatly be so tieing this to html doesn't really help. Thanks all the same dangph
Matt Alcock
Nice! I'll point out that the Cairo library I mention in my answer has PDF and SVG "backends", so that the same code can be used to generate these different formats. But I like the didactic simplicity of your answer. +1
Jonathan Feinberg