How can I make the Xtick and Ytick labels of my axes utilize the LaTeX fonts in MATLAB 8.1 (R2013a)?
20 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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.
Réponse acceptée
MathWorks Support Team
le 25 Avr 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.
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Axis Labels dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!