How can I have two x-labels below x axis showing both LATITUDE and LONGITUDE points?
8 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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...
0 Commenti
Risposta accettata
Star Strider
il 8 Set 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 Commenti
Sreeraj T
il 16 Mag 2021
Modificato: Sreeraj T
il 16 Mag 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
il 17 Mag 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?
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Characters and Strings in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!