How to adjust x-axis in a plot?

조회 수: 4 (최근 30일)
UTKARSH VERMA
UTKARSH VERMA 2021년 8월 20일
편집: ANKUR KUMAR 2021년 8월 23일
Hi,
I am trying to plot a global picture (as shown in figure attached) where my x-axis is from 180 to -180 longitudes but I need to adjust it to start from 0 longitudes and and end with just before 0 longitudes (a sample is also shown).
Please suggest how to achieve that?
Main Figure:
Main figure
How I want:

채택된 답변

ANKUR KUMAR
ANKUR KUMAR 2021년 8월 20일
편집: ANKUR KUMAR 2021년 8월 23일
You can use circshift to rotate your data in a circular fashion. Once you have the circular shifted data, you can just manipulate the coastlon to get the longitudenal range starting from 0 to 360.
Here is an example using reanalysis data.
clc
clear
file='gdas.txt'; % this is really a netcdf data,
% %but I have changed just the file extension to attach this file here in the answers
lon=ncread(file,'lon');
lat=ncread(file,'lat');
tmp=ncread(file,'tmp');
load coastlines
figure
contourf(lon, lat, tmp', 'linecolor','none')
hold on
plot(coastlon, coastlat, 'k-','LineWidth',0.2)
caxis([200 320])
colormap(jet(12))
daspect(ones(1,3))
xlim([-180 180])
colorbar
coastlon=mod(coastlon,360);
coastlon(abs(diff(coastlon))>100)=nan; % commenting this line results into mutiple
% horizontal lines in the plot
figure
contourf(lon, lat, circshift(tmp,size(lon,1)/2,1)', 'linecolor','none')
hold on
plot(coastlon-180, coastlat, 'k-','LineWidth',0.2)
index=sum(lon==get(gca, 'XTick'),2);
xticklabels(lon(logical(index))+180)
caxis([200 320])
colormap(jet(12))
daspect(ones(1,3))
colorbar
  댓글 수: 1
UTKARSH VERMA
UTKARSH VERMA 2021년 8월 23일
Hi Ankur,
Thanks for helping, I have done it manually but your code seems more convinient and general method to use to get these type of results.

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

KSSV
KSSV 2021년 8월 20일
To limit axes read about xlim, ylim, axis.
To put up your required lables on the axis read about xticklabel and yticklabel.
  댓글 수: 1
UTKARSH VERMA
UTKARSH VERMA 2021년 8월 20일
Hi, thanks for replying.
I have read all the documents you have mentioned but, I didn't find the solution also I tried rearranging the longitudes where it starts from 0 longitude and end with 0 but it's showing following error:
Error using contourf (line 57)
Vector X must be strictly increasing or strictly decreasing with no repeated values.
The above error is because my data longitude values starts from -180 to 180.

댓글을 달려면 로그인하십시오.


Steven Lord
Steven Lord 2021년 8월 20일
Since you're working with map data, you may want to explore the map axes that is part of Mapping Toolbox if this toolbox is available to you. There are a number of properties of map axes that you can control (including projection as well as longitude and latitude limits) that may be of use to you in creating this map graphic.
  댓글 수: 1
UTKARSH VERMA
UTKARSH VERMA 2021년 8월 23일
Hi Steven,
Thanks for your suggestion, I will explore map axes.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Geographic Plots에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by