sobota, 30 marca 2013

Modifying matplotlib's hexbin to scale hexes

When showing radiation data with matplotlib's hexplot I wanted to somehow include also statistical uncertainties. I didn't see any solution with standard functionality but I came up with a simple modification to make hexes with large uncertainties smaller.

Actual scaling of the hexes is done by these few lines (polygons in matplotlib are just arrays of vertices):
My modification can actually scale hexes with an arbitrary function of bin counts. And if you provide C parameter reduce_C_function can be separately set for scaling. If you want to just scale hexes according to counts in each bin you can use arctan to restrict scaling to [0,1):
Which produces a plot like this:

For radiation data I want hex color to indicate an average radiation in bin's area so reduce_C_function is set to mean. On the other hand uncertainty of measurement is square root of total counts in bin's area, so hexbin_reduce_C_function is set to sum.

Full code prepared as a separate module: https://gist.github.com/anonymous/5278510

Brak komentarzy:

Prześlij komentarz