Smooth interpolation of a pcolor plot

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 Comments

I woud try 'cubic' or 'spline' at the end of your interp2 and since I can't see your data, check that LL and DD are much larger than LA and DE. But I wonder if interp2 is really needed since griddata ccould do 'cubic' and 'v4' methods of interpolation directly to LL and DD instead of LA and DE.
The 'cubic' method in griddata created a similar graph to the first graph I showed above. It still seems strecthed out in the x direction. Anyother suggestions?
  1. Did you remove the interp2?
  2. Again without your data, what is the result of unique(L),unique(D)? I think you want to select an even spacing of griddata interpolated points over the min and max of each?
  3. The roundness of the colored areas of the ODV plots seem to indicate the same lat and depth spacing were used or at least the depth had a coarser gridding than yours. ODE description on website talks about specialized processing to make these presentations look better; perhaps they form curves to the local peaks and valleys and ignore the minutia?
Yes I removed the interp2 and instead used
tt = griddata(L,D,temp,LL,DD,'cubic');
pcolor(LL,DD,tt)
So no longer using the unique(L) and unique (D).
The same data points are being used in both plots.
So I think it must be my #3: I assume the white areas are area without data points? If so how is it possible that ODV has created contours where no data exists? I think that without seeing the actuall data I'm at a loss to explain how ODV has created artifacts like this that MATLAB seems to have no (or NaN, or ?) data for
@Kacey Lange, so did you find anything? Hopefully yes, otherwise without looking at the actual data I'm probably of no further assistance.
No I didn't, but thank you for helping me! I have accepted it the way it is for now

Sign in to comment.

Answers (1)

arushi
arushi on 21 Dec 2023
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

Categories

Find more on Interpolation in Help Center and File Exchange

Asked:

on 15 Jun 2022

Answered:

on 21 Dec 2023

Community Treasure Hunt

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

Start Hunting!