How do I fix axis labels and numbers?

4 vues (au cours des 30 derniers jours)
Lauren Pressley
Lauren Pressley le 9 Oct 2021
Modifié(e) : Dave B le 12 Oct 2021
I had to use camroll to rotate my image so the x-axis is not the y and the y is now the x-axis. I would like to drop my x-axis down to the bottom of the contour plot. I also want to make it so instead of 0-360 I want the x-axis labels to be from 0 to 720. Either going up by 60 or 120. With the Y-axis I want it from 0 to 180 going up by 30. The contour plot shows a map of the world sea surface temperature anomalies replicated twice so the y is 180 degrees and the x is 720 degrees.
The code:
clear all;
%SST from Jan 1854-Sep 2021, Precip from Jan 1948-Dec 2020
sst=ncread('sst.mnmean.nc','sst');
time = ncread('sst.mnmean.nc','time');
lat=ncread('sst.mnmean.nc','lat');
lon=ncread('sst.mnmean.nc','lon');
SST1 = sst(:, :, 1753:end);
SST2 = SST1(:,:,1:252);
%Every 7/12 for every year
p=ncread('prate.sfc.mon.mean.nc','prate');
Precip = p(:,:,625:end);
%Try 1: Grab all July, remove mean, plot spatial pattern of SSTA over
%years, Global SST anomaly map
%SST Anomaly
Months = 1:252
Months1 = Months(7:12:252)
data_jul2 = SST2(:,:,Months1);
monthly_means = mean(data_jul2,3);
data_mat_ac_removed = data_jul2-repmat(monthly_means,1,1,21);
data_mat_ac_removed1 = [data_mat_ac_removed;data_mat_ac_removed];
% data_mat_ac_removed = data_jul2 - monthly_means;
figure(1);
contourf(squeeze(data_mat_ac_removed1(:,:,1)))
camroll(270)
c = colorbar;
c.Label.String = 'Degrees C';
title('OND SST Anomalies 2020')
xlabel('Latitude')
ylabel('Longitude')
  2 commentaires
Star Strider
Star Strider le 9 Oct 2021
Even when zipped, the ‘sst.mnmean.nc’ file is 77.7 MB, and so it can’t be uploaded here.
Providing answers to this is limited to those who have the Mapping Toolbox licensed and installed.
Oh, well ...
Tanmay Das
Tanmay Das le 12 Oct 2021
Hi, can you please provide 'prate.sfc.mon.mean.nc' file for further investigation?

Connectez-vous pour commenter.

Réponses (1)

Dave B
Dave B le 12 Oct 2021
Modifié(e) : Dave B le 12 Oct 2021
I think you want your y-axis (which, because of your use of camroll is the horizontal axis) at the bottom. Because MATLAB still thinks of this as the y-axis, it thinks of top as left and bottom as right, so setting the YAxisLocation property does the trick.
For the ticks and tick labels, it sounds like you don't want to change the limits but just the display of tick labels.
An couple of ideas to consider:
  • maybe this would have been easier if you had transposed the data rather than the plot? (similarly you could provide x and y co-ordinates for contourf and MATLAB would pick appropriate ticks)
  • do you want an axis equal on there to make the aspect ratio not look so distorted?
h=openfig('foo.fig');
copyobj(h.Children, figure) %hack to get the figure to show up in web
set(gca, 'YAxisLocation', 'right', ...
'YTick', 0:30:360, ...
'YTickLabels',0:60:720, ...
'XTick', 0:15:90, ...
'XTickLabels', 0:30:180)
copyobj(get(gcf,'Children'), figure)
cb = findobj(gcf,'Type','colorbar');
cb.Location='SouthOutside';
axis equal

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by