How can I make the Xtick and Ytick labels of my axes utilize the LaTeX fonts in MATLAB 8.1 (R2013a)?

53 views (last 30 days)
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.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 25 Apr 2013
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.

More Answers (0)

Categories

Find more on Labels and Annotations in Help Center and File Exchange

Products


Release

R2013a

Community Treasure Hunt

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

Start Hunting!