How can I make the Xtick and Ytick labels of my axes utilize the LaTeX fonts in MATLAB 8.1 (R2013a)?
조회 수: 19 (최근 30일)
이전 댓글 표시
I used the following code to set all my text objects to have LaTeX as their default interpreter as follows:
set(0,'DefaultTextInterpreter', 'latex')
However when I create a simple plot with a TEXT object:
plot(1:10);
text(5, 5, '1 2 3 4 5 6 7 8 9 0');
I find that the Xtick and Ytick labels have different fonts from the TEXT object I created.
I would like the labels to appear the same as the text objects.
채택된 답변
MathWorks Support Team
2013년 4월 25일
The ability to make the Xtick labels and Ytick labels utilize the same font as TEXT objects with LaTeX as their interpreter is not available in MATLAB 8.1 (R2013a).
To workaround this issue create a TEXT object for each individual label as the following example illustrates:
%%Generate figure and remove ticklabels
close all;
plot(1:10);
set(gca,'yticklabel',[], 'xticklabel', []) %Remove tick labels
%%Get tick mark positions
yTicks = get(gca,'ytick');
xTicks = get(gca, 'xtick');
ax = axis; %Get left most x-position
HorizontalOffset = 0.1;
%%Reset the ytick labels in desired font
for i = 1:length(yTicks)
%Create text box and set appropriate properties
text(ax(1) - HorizontalOffset,yTicks(i),['$' num2str( yTicks(i)) '$'],...
'HorizontalAlignment','Right','interpreter', 'latex');
end
%%Reset the xtick labels in desired font
minY = min(yTicks);
verticalOffset = 0.2;
for xx = 1:length(xTicks)
%Create text box and set appropriate properties
text(xTicks(xx), minY - verticalOffset, ['$' num2str( xTicks(xx)) '$'],...
'HorizontalAlignment','Right','interpreter', 'latex');
end
Please be aware that when using this workaround for subplots, each time a new axes is added to the figure window, there may be a small shift in positioning of the axes. It is likely necessary to add the text object after all the subplots have been rendered.
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Axis Labels에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!