Smooth interpolation of a pcolor plot
42 次查看(过去 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);
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1033745/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1033750/image.gif)
7 个评论
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.
回答(1 个)
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:
- 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
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!