How to display coordinate labels in Latex using Geographic Axes
40 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Enrico Anderlini
il 12 Apr 2020
Commentato: Allison Chua
il 23 Nov 2024 alle 19:28
I am trying to display data in a map using the geographic plot introduced in MATLAB v2019a. I am using v2019b.
The plot works really well for the default text. However, I would like to switch the interpreter to Latex to keep the style consistent with my article.
Using
gx.LatitudeAxis.TickLabelInterpreter = 'Latex';
gx.LongitudeAxis.TickLabelInterpreter = 'Latex';
correctly changes the x- and y-labels to Latitude and Longitude in Latex. However, the coordinates disappear (i.e. 55° N for example). I have tried to get the coordinates to reappear by trying different commands. My code is as follows. I will keep on trying, but help would be greatly appreciated!
%% Visualise the data on a map:
% Create a new figure:
figure;
% Create a GeographicAxes.
gx = geoaxes;
for i=1:nf
geoplot(latidue{i},longitude{i});
hold on;
end
hold off;
% geolimits([yy,yy],[xx,xx]);
gx.LatitudeAxis.TickLabelInterpreter = 'Latex';
gx.LongitudeAxis.TickLabelInterpreter = 'Latex';
gx.LatitudeAxis.Label.FontSize = 16;
gx.LongitudeAxis.Label.FontSize = 16;
gx.LatitudeAxis.Visible = 'on';
gx.LongitudeAxis.Visible = 'on';
gx.LatitudeAxis.TickLabelFormat = 'dms';
gx.LongitudeAxis.TickLabelFormat = 'dms';
gx.LatitudeAxis.TickLabelRotation = 0;
gx.LongitudeAxis.TickLabelRotation = 0;
set(gcf,'color','w');
l = legend(unit_name,'NumColumns',4,'Position',newPosition,...
'Units',newUnits,'Orientation','horizontal');
set(l,'Interpreter','Latex','FontSize',12);
0 Commenti
Risposta accettata
Ameer Hamza
il 12 Apr 2020
This happens because the TickLabel contains a degree character (°) instead of using a latex symbol \circ. The tex interpreter is able to work with it, but the latex interpreter does not recognize this character. Hence it renders nothing. The following shows a workaround by replacing ° with a $^{circ}$, which latex can understand.
figure;
% Create a GeographicAxes.
gx = geoaxes;
% geolimits([yy,yy],[xx,xx]);
gx.LatitudeAxis.TickLabelInterpreter = 'Latex';
gx.LongitudeAxis.TickLabelInterpreter = 'Latex';
gx.LatitudeAxis.Label.FontSize = 16;
gx.LongitudeAxis.Label.FontSize = 16;
gx.LatitudeAxis.Visible = 'on';
gx.LongitudeAxis.Visible = 'on';
gx.LatitudeAxis.TickLabelFormat = 'dms';
gx.LongitudeAxis.TickLabelFormat = 'dms';
gx.LatitudeAxis.TickLabelRotation = 0;
gx.LongitudeAxis.TickLabelRotation = 0;
set(gcf,'color','w');
% add following lines to your code
gx.LatitudeAxis.TickLabels = strrep(gx.LatitudeAxis.TickLabels, '°', '$^{\circ}$');
gx.LongitudeAxis.TickLabels = strrep(gx.LongitudeAxis.TickLabels, '°', '$^{\circ}$');
4 Commenti
Aymane ahajjam
il 1 Feb 2024
Thank you for your help! I had the same problem!
An additional thing is to have the longitude and latitude labels to be in latex too using:
gx.LatitudeLabel.Interpreter = 'latex';
gx.LongitudeLabel.Interpreter = 'latex';
Allison Chua
il 23 Nov 2024 alle 19:28
Thank you, @Ameer Hamza! I have literally spent hours on this as I need consistent formatting for the plots going into my thesis. You are a lifesaver!
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Graphics Object Properties 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!