How to display coordinate labels in Latex using Geographic Axes

34 views (last 30 days)
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);

Accepted Answer

Ameer Hamza
Ameer Hamza on 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}$');
  3 Comments
Aymane ahajjam
Aymane ahajjam on 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';

Sign in to comment.

More Answers (0)

Categories

Find more on Geographic Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!