0
votes

I am trying to plot a contour plot of non rectangular data without any interpolation (I do not want to use the meshgrid module here). Therefore I tried following code:

x_co=data_U[:,0] #-> 22450 rows
y_co=data_U[:,1] #-> 22450 rows
U_co=data_U[:,3] #-> 22450 rows
u_im=np.zeros((len(u_co),len(u_co))) #24450,22450 array
u_im[zip(y_co,x_co)]=U_co #22450,22450 array

fig1.plt.figure()
plate=pltcontourf(x_co,y_co,u_im,vmin=-10, vmax=10,extent=[x_co[0],x_co[-1],y_co[0],y_co[-1]],origin='upper',levels=level,cmap=plt.cm.jet,aspect='auto')   
plt.show

I do always run out of memory, so the idea is to decrease the resolution by np.meshgrid(xi,yi) with 1000,1000 points. Next step would be interpolating data U_co on the new meshgrid, but the triangulation here connects vertices where it should not. So my non regular grid is not realistic given by the interpolation.

Any advice?

1

1 Answers

0
votes

You can use scipy.interpolate.griddata to interpolate the data with the method=nearest (see here). Without the data it is difficult to help more but the code would look something like,

import numpy as np
from scipy.interpolate import griddata

x_co=data_U[:,0] #-> 22450 rows
y_co=data_U[:,1] #-> 22450 rows
U_co=data_U[:,3] #-> 22450 rows
interp_grid = np.meshgrid(1000,1000)
newgrid = griddata((x_co, y_co), U_co, interp_grid, method='linear')

plt.imshow(newgrid.T, origin='lower')
plt.show()

If you've got a uniform grid, I'd suggest using imshow instead of contourf as it should be faster.