Plot (x, y, z) triples on 2d plane with a colormap
Question: I'm using `python2` and `matplotlib`.

I have lots of triples `(x, y, z)`. I need to plot them as a kind of
**histogram/heatmap** on a 2d plane with the axes `x` and `y` and a color
indicating `z`.

The main problem is that x and y are not on any kind of grid but vary freely,
so some kind of interpolation is needed.

I tried `contour(X, Y, Z)`, but this takes Z as a 2d array, which means it
needs the values on a grid.


Answer: I like using `hexbin` with it's `C` input option for this sort of thing. For
example, if you've parsed your data from tuple-triples into `x_arr`, `y_arr`
and `z_arr` arrays, you could do:

    
    
    from matplotlib.pyplot import hexbin
    
    hexbin(x_arr, y_arr, C=z_arr)
    

This implicitly averages the data over the hexagonal bins. You can change the
`reduce_C_function` option if you want something different than a simple
average. You can change the number of bins with the `gridsize` option.

