How to display coordinate labels in Latex using Geographic Axes
조회 수: 28 (최근 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);
댓글 수: 0
채택된 답변
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}$');
댓글 수: 4
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';
Allison Chua
2024년 11월 23일 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!
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Graphics Object Properties에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!