irregularly spaced dataset visualization in python

Viewed 44

I want to visualize a blood flow simulation created in Paraview using an irregularly spaced grid in the XY directions. contour, imshow or pcolor python functions require regular grids. Interpolation using griddata or using tricontour plot gives me a bad visualization. Any better ideas are highly appreciated. Her is my attempt,

# Asuming xf,yf and uCFD are known

x = xf *10
y = yf *1.0

title = "U_CFD"
dirname = "tt.png"
fontsize=8.5
labelsize=8.5
z = uCFD.reshape(101 , 28054)[70,:]   #get u_CFD at time step 70

npts = 5000
fig = plt.figure()
xi = np.linspace(x.min(),x.max(),npts)
yi = np.linspace(y.min(),y.max(),npts)
imgG = ImageGrid(fig, 111, direction="row", nrows_ncols=(1,1), 
                 label_mode="1", axes_pad=0.8, share_all=False, 
                 cbar_mode="each", cbar_location="right", 
                 cbar_size="5%", cbar_pad=0.0)

minmax = [np.min(z), np.max(z)]
kwargs = dict(levels=np.linspace(minmax[0],minmax[1], 60),cmap="seismic", 
              vmin=minmax[0], vmax=minmax[1])

# CREATE PLOTS
pcfsets = []
ax = imgG[0]
#zi = griddata((x, y), z[timeStp,:], (xi[None,:], yi[:,None]), method='cubic')  ## I tried with this option but it does not help
triang = tri.Triangulation(x, y)
interpolator = tri.LinearTriInterpolator(triang,  z)
Xi, Yi = np.meshgrid(xi, yi)
zi = interpolator(Xi, Yi)

pcf = ax.contourf(xi, yi, zi, **kwargs)

cb = ax.cax.colorbar(pcf, ticks=np.linspace(minmax[0],minmax[1],3),  format='%.2e')
ax.cax.tick_params(labelsize=labelsize)
ax.set_title(title, fontsize=fontsize, pad=7)
ax.set_ylabel("y", labelpad=labelsize, fontsize=fontsize, rotation="horizontal")
ax.set_xlabel("x", fontsize=fontsize)
ax.tick_params(labelsize=labelsize)
ax.set_xlim(x.min(), x.max())
ax.set_ylim(y.min(), y.max())
ax.set_aspect("equal")

fig.set_size_inches(20,20,True)
fig.subplots_adjust(left=0.7, bottom=0, right=2.2, top=1, wspace=None, hspace=None)
plt.tight_layout()
plt.savefig(dirname, dpi=300 , bbox_inches='tight')
plt.close("all" , )

The result is shown hereenter image description here

0 Answers
Related