필터 지우기
필터 지우기

How to put degree sign in tick labels with latex interpreter?

조회 수: 41 (최근 30일)
Pawel Kekus
Pawel Kekus 2020년 4월 8일
댓글: Ameer Hamza 2020년 4월 8일
Hi there,
I need to put the degree sign on tick labels while using the latex interpreter, in order to retain LaTeX font and formatting, as in the following MWE:
figure
plot([1,2],[1,2])
set(gca,'TickLabelInterpreter','latex')
xticks(1:0.5:2)
xtickformat('%.1f ^{\circ}')
Without latex interpreter, it works correctly (other than not rendering the \circ symbol), but when interpreter is set to latex, all tick labels disappear completely.
I don't understand where this incompatibility comes from, since I've used '^{\circ}' together with latex interpreter just about everywhere else in the figure (title, axis labels, legend, legend title) without any issues. I also don't know how to get around it, and wasn't able to find anything helpful. Pasting the symbol ° ('%.1f°') causes the tick labels to disappear too.
Any help would be greatly appreciated.

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 4월 8일
try something like this
figure
plot([1,2],[1,2])
set(gca,'TickLabelInterpreter','latex')
xticks(1:0.5:2)
ax = gca;
xtickformat('%.1f')
ax.XTickLabel = strcat(ax.XTickLabel, '$^{\circ}$');
  댓글 수: 2
Pawel Kekus
Pawel Kekus 2020년 4월 8일
Perfect, thank you! This made me realise that I forgot about the $ signs, and putting them in the xtickformat stopped tick labels from disappearing, but the degree symbol still wasn't rendered. Your solution worked just fine.
Thanks again.
Ameer Hamza
Ameer Hamza 2020년 4월 8일
Glad to be of help.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Labels and Annotations에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by