Scipy Griddata results do not align with original data

Viewed 136

I am using griddata to interpolate some 3d data. However, when plotting the resulting array, it appears that the griddata output dimensions do not correspond to the original data as can be seen below. It seems as though the grid dimensions are out of order, and that the grid is rotated in some way, but I don't understand why this misalignment is occurring.

import numpy as np
import matplotlib.pyplot as plt
from scipy.interpolate import griddata

num_points = 100

p0 = np.random.uniform(0.5,1,num_points)
p1 = np.random.uniform(0,1,num_points)
p2 = np.random.uniform(0,0.5,num_points)

params = np.array([p0, p1, p2]).T

data = np.random.uniform(0,1,num_points)

num_params = params.shape[-1]
resolution = 50
data_gridded = griddata(
        params,
        data,
        tuple(np.meshgrid(*([np.linspace(0,1,resolution)]*num_params))),
        method="linear",
        fill_value=0,
    )

fig, ax = plt.subplots(1,3, figsize=[10,5])

ax[0].scatter(p0, p1, c=data, cmap="Greys")
ax[0].imshow(np.mean(data_gridded, axis=2), extent=[0,1,0,1], origin="lower", cmap="Greys")
ax[0].title.set_text('P0 vs P1')

ax[1].scatter(p0, p2, c=data, cmap="Greys")
ax[1].imshow(np.mean(data_gridded, axis=1), extent=[0,1,0,1], origin="lower", cmap="Greys")
ax[1].title.set_text('P0 vs P2')

ax[2].scatter(p1, p2, c=data, cmap="Greys")
ax[2].imshow(np.mean(data_gridded, axis=0), extent=[0,1,0,1], origin="lower", cmap="Greys")
ax[2].title.set_text('P1 vs P2')
plt.show()

plot output

0 Answers
Related