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

8 visualizaciones (últimos 30 días)
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...

Respuesta aceptada

Star Strider
Star Strider el 8 de Sept. de 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 comentarios
Sreeraj T
Sreeraj T el 16 de Mayo de 2021
Editada: Sreeraj T el 16 de Mayo de 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 el 17 de Mayo de 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?

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Characters and Strings en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by