python - Creating a heatmap by sampling and bucketing from a 3D array -
i have experimental data exists so: x = array([1, 1.12, 1.109, 2.1, 3, 4.104, 3.1, ...]) y = array([-9, -0.1, -9.2, -8.7, -5, -4, -8.75, ...]) z = array([10, 4, 1, 4, 5, 0, 1, ...]) if it's convenient, can assume data exists 3d array or pandas dataframe : df = pd.dataframe({'x': x, 'y': y, 'z': z}) the interpretation being, every position x[i], y[i] , value of variable z[i] . these not evenly sampled , there parts "densely sampled" (e.g. between 1 , 1.2 in x ) , others sparse (e.g. between 2 , 3 in x ). because of this, can't chuck these pcolormesh or contourf . what instead resample x , y evenly @ fixed interval , aggregate values of z . needs, z can summed or averaged meaningful values, not problem. naïve attempt this: x = np.arange(min(x), max(x), 0.1) y = np.arange(min(y), max(y), 0.1) x_g, y_g = np.meshgrid(x, y) nx, ny = x_g.shape z_g = np.full(x_g.shape, np.nan) ix in range(nx - 1): jx in range(ny - 1): ...