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

8 Ansichten (letzte 30 Tage)
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...

Akzeptierte Antwort

Star Strider
Star Strider am 8 Sep. 2014
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 Kommentare
Sreeraj T
Sreeraj T am 16 Mai 2021
Bearbeitet: Sreeraj T am 16 Mai 2021
@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 am 17 Mai 2021
@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?

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Characters and Strings finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by