How to display coordinate labels in Latex using Geographic Axes
40 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Enrico Anderlini
am 12 Apr. 2020
Kommentiert: Allison Chua
am 23 Nov. 2024 um 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 Kommentare
Akzeptierte Antwort
Ameer Hamza
am 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 Kommentare
Aymane ahajjam
am 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
am 23 Nov. 2024 um 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!
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Graphics Object Properties finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!