Clear Filters
Clear Filters

Smooth interpolation of a pcolor plot

70 views (last 30 days)
Kacey Lange
Kacey Lange on 15 Jun 2022
Answered: arushi on 21 Dec 2023
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));
tt = griddata(L,D,temp,LA,DE);
shading interp
a.Label.String = 'Temperature (\circC)';
a.Label.FontSize = 12;
set(gca, 'YDir','reverse')
Jeffrey Clark
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
Kacey Lange on 29 Jun 2022
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 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 -
Link to the documentation of imgaussfilt -
Link to the documentation of scatteredInterpolant -
Hope this helps.
Thank you


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!