How can I have two x-labels below x axis showing both LATITUDE and LONGITUDE points?

조회 수: 8 (최근 30일)
Both lat/lon spacing are equal and forms square grid boxes. I have another variable at y-axis.
I have attached one figure for illustration...

채택된 답변

Star Strider
Star Strider 2014년 9월 8일
I don’t have your code or figure, so this is the best I can do:
x = linspace(0,10*pi,1000);
y = sin(2*pi*sin(x));
figure(1)
plot(x,y)
grid
axis tight
ymin = min(ylim);
yrng = diff(ylim);
xt = get(gca, 'XTick');
set(gca, 'XTickLabel', []);
nrxt = size(xt,2);
latvct = linspace(71.59, 24.06, nrxt);
lat_txt = cellstr(strsplit(num2str(latvct,'%.2f '),' '));
text([(xt(1)-xt(2))*0.5 xt], ones(1,nrxt+1)*ymin-0.05*yrng, ['Lat ' lat_txt],'HorizontalAlignment','center')
lngvct = linspace(100.71, 75.54, nrxt);
lng_txt = cellstr(strsplit(num2str(lngvct,'%.2f '),' '));
text([(xt(1)-xt(2))*0.5 xt], ones(1,nrxt+1)*ymin-0.1*yrng, ['Lon' lng_txt],'HorizontalAlignment','center')
Everything you likely need is here, but you will obviously have to experiment with it to get the result you want in your application.
It produces:
  댓글 수: 4
Sreeraj T
Sreeraj T 2021년 5월 16일
편집: Sreeraj T 2021년 5월 16일
@sachin patel, i am not sure you got the answer for the query. Anyway, this is mine. What I found is that the spacing is controlled by
ymin-0.05*yrng
and
ymin-0.12*yrng
You may change the numbers and see it for yourself. If you increase the second no. (i.e. 0.12) substantially, then the label may 'go outside the plot'.
Sreeraj T
Sreeraj T 2021년 5월 17일
@Star Strider I am trying to understand this code. If i replace x by
log10(linspace(12.858000,690.02002,605)')
, then the texts 'Lat' and 'Lon' no longer appears. Why is that happening?

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by