Smooth interpolation of a pcolor plot
Show older comments
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
Jeffrey Clark
on 16 Jun 2022
Edited: Jeffrey Clark
on 16 Jun 2022
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.
Kacey Lange
on 21 Jun 2022
Jeffrey Clark
on 23 Jun 2022
- Did you remove the interp2?
- 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?
- 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?
Kacey Lange
on 23 Jun 2022
Jeffrey Clark
on 23 Jun 2022
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

Jeffrey Clark
on 29 Jun 2022
@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
on 29 Jun 2022
Answers (1)
arushi
on 21 Dec 2023
0 votes
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:
- 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.
- 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.
- Apply a smoothing filter: You can apply a smoothing filter to the interpolated data. This can be done using functions like smoothdata, imgaussfilt, or a custom convolution filter.
- Regularize the data: If your data is very unevenly distributed, consider regularizing it by averaging within bins of latitude and depth before interpolating.
- 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
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!