Smooth interpolation of a pcolor plot

55 次查看(过去 30 天)
Hello all,
I am trying to recreate a plot that I created in Ocean Data View (ODV) where my x = depth (D), y = latitude (L), and z = temperature (temp). I am trying to do this by using an interpolated pcolor plot. In ODV I am able to interpolate by using the DIVA (Data-Interpolating Variational Analysis) method. This comes out much nicer than what it does in matlab because of how spread out my data is. In matlab, my interpolated plot is not very smooth and seems stretched out in the x direction compared to my plot in ODV. What I am trying to do is to smooth out the graph and not have as much stretching. By trying to fix this, I tried to create a larger meshgrid to create more points; however, my plot still looks the same. No error pops up. I have attached both images.
tvl = [l d t];
totvl = rmmissing(tvl);
L = totvl(:,1);
D = totvl(:,2);
temp = totvl(:,3);
[LL,DD] = meshgrid((15:0.1:35),(0:0.1:200));
[LA,DE]=meshgrid(unique(L),unique(D));
tt = griddata(L,D,temp,LA,DE);
TT=interp2(LA,DE,tt,LL,DD);
figure
pcolor(LL,DD,TT)
shading interp
colormap(tempcolormap);
colorbar
a=colorbar;
a.Label.String = 'Temperature (\circC)';
a.Label.FontSize = 12;
set(gca, 'YDir','reverse')
xlabel('Latitude','FontSize',20);
ylabel('Depth','FontSize',20);
  7 个评论
Jeffrey Clark
Jeffrey Clark 2022-6-29
@Kacey Lange, so did you find anything? Hopefully yes, otherwise without looking at the actual data I'm probably of no further assistance.
Kacey Lange
Kacey Lange 2022-6-29
No I didn't, but thank you for helping me! I have accepted it the way it is for now

请先登录,再进行评论。

回答(1 个)

arushi
arushi 2023-12-21
Hi Kacey,
I understand that you are not able to get a smoother plot in MATLAB. The griddata function in MATLAB can sometimes produce less smooth results, especially if the data is sparse or unevenly distributed. The DIVA method in Ocean Data View (ODV) uses a variational approach that can handle such data better.
To improve the smoothness of the plot in MATLAB, you can try the following steps:
  1. Increase the resolution of the interpolation grid:Based on the provided information, I see that you have attempted it, but I recommend ensuring that the grid is fine enough to capture the variations in your data. You can adjust the step size in meshgrid to create a denser grid.
  2. Use other interpolation methods: MATLAB's interp2 function allows you to specify different interpolation methods such as 'linear', 'nearest', 'cubic', or 'spline'. Experiment with these to see if they provide a smoother result.
  3. Apply a smoothing filter: You can apply a smoothing filter to the interpolated data. This can be done using functions likesmoothdata, imgaussfilt, or a custom convolution filter.
  4. Regularize the data: If your data is very unevenly distributed, consider regularizing it by averaging within bins of latitude and depth before interpolating.
  5. Use other interpolation tools: MATLAB has other tools for interpolation that may provide better results, such as scatteredInterpolant. These can offer more flexibility in how the interpolation is performed.
Link to the documentation of interpolation mehtods - https://www.mathworks.com/help/matlab/ref/interpn.html
Link to the documentation of imgaussfilt - https://www.mathworks.com/help/images/ref/imgaussfilt.html
Link to the documentation of scatteredInterpolant - https://www.mathworks.com/help/matlab/ref/scatteredinterpolant.html
Hope this helps.
Thank you

类别

Help CenterFile Exchange 中查找有关 Interpolation 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by