0
votes

I need assistance making a nice contour plot. I have data from an underwater glider that dives and climbs repeatedly from the surface of the ocean to around 30 m, in this case.

I think my issue is with interpolating the data, and I am not sure how to proceed. Here is the contour plot of density I have generated this far.

Contour plot of density

The Contour plot of density was generated using this code

xlin = linspace(min(time),max(time),500);
ylin = linspace(min(depth),max(depth),500);
[X,Y] = meshgrid(xlin,ylin);
Z = griddata(time,depth,density,X,Y);
[C,h] = contour(X,Y,Z,[1022.0, 1022.5, 1023.0, 1023.5, 1024.0, 1024.5, 1025.0, 1025.5, 1026.0],'color',[0.5 0.5 0.5]);
v = [1022.0, 1022.5, 1023.0, 1023.5, 1024.0, 1024.5, 1025.0, 1025.5, 1026.0];
clabel(C,h,v,'fontsize',8);
set(gca,'ydir','reverse');

I want the plot to have smooth contour lines. Once I get the contour plot to look good I will overlay it on salinity and temperature scatter plots.

Please let me know how I can make a better looking contour plot.

Is it an issue with interpolation? Or the way I gridded the data?

Thanks very much! Please be specific and give code examples if you've played with the data.

Here is the time, depth, and density matlab data: https://www.dropbox.com/s/agi70zh7haggf07/data.mat?dl=0

1
How come you generate the spatial data (X,Z) with time and depth? - marsei
I don't have a good answer for that, only because I was following other peoples methods. If you have a better suggestion please do tell! - B.K.I

1 Answers

1
votes

The problem is that bunch of your interpolated data are missing. I mean that Z has a bunch of NaNs:

xlin = linspace(min(time),max(time),500);
ylin = linspace(min(depth),max(depth),500);
[X,Y] = meshgrid(xlin,ylin);
Z = griddata(time,depth,density,X,Y);
%surf(X,Y,Z) %also interesting
spy(isnan(Z));

Result:

nans in data

Your input data are somehow ill-defined, and griddata gives up. Here's why:

>> sum(isnan(density))

ans =

        3174

Fix the NaNs in your raw data, and you'll most probably fix the plot.

Update

I threw away your NaNs:

inds=~isnan(density);
time=time(inds);
depth=depth(inds);
density=density(inds);

to see how the result looks like. It turns out that your original code is already looking OK to me!

Original on the left, de-NaNed version on the right:

original contournew contour

So... maybe your datetime transformation is off? Or your time limits, not showed in your original code?