How to display coordinate labels in Latex using Geographic Axes

34 次查看(过去 30 天)
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);

采纳的回答

Ameer Hamza
Ameer Hamza 2020-4-12
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 个评论
Aymane ahajjam
Aymane ahajjam 2024-2-1
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';

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Geographic Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by