Combining multiple colors and latex commands as tick labels

15 ビュー (過去 30 日間)
Leo Simon
Leo Simon 2020 年 4 月 21 日
コメント済み: Leo Simon 2020 年 4 月 21 日
I want to have some ticklabels as colored symbols and others as symbols like \bar{x}. These desires seem to be incompatible.
To get the colored symbols I need the 'tex' interpreter; to get \bar{x} I need the 'latex' interpreter.
The following example illustrates the problem. If you run it to the keyboard, you'll see the colored lsymbols together with \$\bar{x}\$
This seems to be because the tex intepreter doesn't know what to do with the \bar command. Same problem with \tilde, \hat, etc.
If you go past the keyboard and switch interpreters, you'll see but the colored symbols disappear, because it seems the latex interpreter doesn't know what to do with the colored symbols. Is there any way to reconcile this incompatibility? Thanks!
plot(1:2);
XTickLabels=get(gca,'XTickLabel');
XTickLabels{1}='$\bar{x}$';
XTickLabels{2}='\color{red}\lambda';
XTickLabels{3}='\color{blue}\theta';
set(gca,'XTickLabel',XTickLabels);
set(gca,'TickLabelInterpreter','tex');
keyboard;
set(gca,'TickLabelInterpreter','latex');

採用された回答

Mehmed Saad
Mehmed Saad 2020 年 4 月 21 日
編集済み: Mehmed Saad 2020 年 4 月 21 日
You can use this instead of that
plot(1:2);
x = gca;
pos = x.XTick;
poy = min(ylim)-0.05;
x.XTickLabel= ' ';
sybs = {'$\bar{x}$','\lambda','\theta','$\bar{x}$','\lambda','\theta','$\bar{x}$',...
'\lambda','\theta','$\bar{x}$','\lambda'};
intp = {'latex','tex','tex','latex','tex','tex','latex','tex','tex','latex','tex'};
for i=1:length(pos)
text(pos(i),poy,sybs{i},'Interpreter',intp{i},'Color',rand(1,3),'FontSize',15,...
'HorizontalAlignment','center','VerticalAlignment','baseline')
end
  1 件のコメント
Leo Simon
Leo Simon 2020 年 4 月 21 日
Perfect, thanks! This means i can abandon matlab's tick label implementation forever, which is very liberating!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLabels and Annotations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by