I have the problem that I want to interpolate data on a meshgrid, but I don’t want to extrapolate it, I just want to interpolate between existing data values.
Specifically, the problem is as follows: I have l, h and u values. l and h span crosssection and have different velocity values (u), which I would like to display as a contour plot.
I think the most important parts of my code are
grid_x1, grid_y1 = np.mgrid[min(l1):max(l1):1391j, min(h1):max(h1):23j]
grid_x2, grid_y2 = np.mgrid[min(l2):max(l2):1786j, min(h2):max(h2):31j]
matrix1 = np.vstack([l1, h1]).T
matrix2 = np.vstack([l2, h2]).T
vel1 = griddata(matrix1, u1, (grid_x1, grid_y1), method="nearest", fill_value=np.nan)
vel2 = griddata(matrix2, u2, (grid_x2, grid_y2), method="nearest", fill_value=np.nan)
and that’s how I create a contourplot:
fig, axs = plt.subplots(nrows=3, ncols=1, layout="constrained")
fig.suptitle("Profil XS 2 - Vergleich Netz 2-0 und 2-1")
ax = axs[0]
contour = ax.contourf(grid_x1, grid_y1, vel1, levels=np.linspace(0, 2, 101), cmap=cm)
cbar = plt.colorbar(contour)
cbar.set_label("U Magnitude [m/s]")
cbar.set_ticks([0, 0.5, 1, 1.5, 2])
ax.xaxis.set_inverted(True)
ax.set_title("Netz 2-0")
ax.set_aspect(10/1)
I have currently loaded 2 data sets and what you see in the first picture is what usually happens, but it should actually look like picture 2. I have also tried cubic and linear as an interpolation method, but that doesn’t work either.
Picture 1
Picture 2
Selina is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.