temperature range of file not seen in plot or matching colorbar

1 Ansicht (letzte 30 Tage)
Aomawa
Aomawa am 20 Mär. 2024
Kommentiert: Aomawa am 20 Mär. 2024
I know the maximum temperature reached in a netcdf file I'm working with is 314 K. However, when I plot it using countourf, neither that temperature nor anything close to it is visible in the plot. And the colorbar color assigned to this max temp does not match what I'm seeing in the plot. Here is the code I'm using:
ncfile1='./ANN_climo.nc';
var1='TS';
tmp1=squeeze(ncread(ncfile1,var1));
lat=ncread(ncfile1,'lat');
lev=ncread(ncfile1,'lev');
lon=ncread(ncfile1,'lon');
%checking max/min temps
max(max(tmp1))
min(min(tmp1))
%plotting
tmp2 = transpose(tmp1);
contourf(lon,lat,tmp2, 'LineStyle','none');
hold on
%adding dotted line for freezing point
contourf(lon,lat,tmp2, [273.0,273.0], 'linestyle', 'none');
contourf(lon,lat,tmp2,[273.0,273.0], 'linestyle', '--', 'linecolor', 'k')
%specifying the colormap
colormap('turbo')
%check default colorbar limits
caxis
set(gca,'fontsize',14);
ylabel('Latitude (\circ)')
xlabel('Longitude (\circ)')
h = colorbar;
xlabel(h,'(K)');
hold off
What am I missing?

Antworten (1)

Cris LaPierre
Cris LaPierre am 20 Mär. 2024
Without the data, we can only speculate.
I suspect you are not seeing it because you have programmatically set the contour line to 273.
contourf(lon,lat,tmp2, [273.0,273.0], 'linestyle', 'none');
From the doc page description of the levels input: "To draw contour lines at a single height k, specify levels as a two-element row vector [k k]"
What if you just try
contourf(lon,lat,tmp2,'linestyle', 'none');
  2 Kommentare
Aomawa
Aomawa am 20 Mär. 2024
Thank you. I tried to upload the netcdf file but it is too large.
My first contourf line is contourf(lon,lat,tmp2, 'LineStyle','none')
Are you saying I am overriding that when I plot the freezing point line on top of it?
Aomawa
Aomawa am 20 Mär. 2024
I just tried it. You were right. Thank you so much. I appreciate it greatly!!!

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Colormaps finden Sie in Help Center und File Exchange

Produkte


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by