Hello everyone,
I want to have subscript labels in axeses in matlab. Let say I have
J = [1 2 3; 4 5 6];
bar(J);
set(gca,'XTickLabel',{'I_0','I_1'});
I can't get I_0 in subscript. How can I do this. I m using Matlab 2009 on Ubuntu.

 採用された回答

Star Strider
Star Strider 2014 年 7 月 13 日

0 投票

Here is one way, there may be others:
J = [1 2 3; 4 5 6];
bar(J);
set(gca,'XTickLabel','');
set(gca, 'XTickLabelMode','manual')
hxt = get(gca, 'XTick')
ypos = min(ylim) - diff(ylim)*0.05;
text(hxt, [1 1]*ypos, {'I_0','I_1'}, 'HorizontalAlignment', 'center')
You will have to experiment with the ypos value for text to put it exactly where you want it. I did my best to make it as adaptive as I could.

5 件のコメント

Image Analyst
Image Analyst 2014 年 7 月 13 日
By the way, usually I have the opposite problem. I often put the title of the image as the filename, and if the filename has an underline in it , it makes the character following the underline a subscript, which looks ridiculous. To avoid that you need to set the interpreter equal to none
title(imageFileName, 'Interpreter', 'none');
Star Strider
Star Strider 2014 年 7 月 13 日
Good point. ‘Axis Properties’ doesn’t have in 'Interpreter' option.
Aravin
Aravin 2014 年 7 月 14 日
編集済み: Aravin 2014 年 7 月 14 日
Dear Strider,
Thank you for your reply. It works well for given example. I want exactly that but when I use it for my real problem where i have 5 xtick values then it gives error that x y should have same dimensions. Could you please modify it so that I can use it.
Example:
J = [1 2 3;4 5 6;7 8 9;10 11 12;13 14 15];
bar(J);
set(gca,'XTickLabel','');
set(gca, 'XTickLabelMode','manual')
hxt = get(gca, 'XTick')
ypos = min(ylim) - diff(ylim)*0.05;
text(hxt, [1 1]*ypos, {'F_0|F_1','F_0|F_2','F_0|F_3','F_0|F_4','F_0|F_5'}, 'HorizontalAlignment', 'center')
And how to make text italic (F_0|F_1) ?
Aravin
Aravin 2014 年 7 月 14 日
I have Figured it out. Thank you.
Star Strider
Star Strider 2014 年 7 月 14 日
My pleasure!
GMT-6 here so I’m just now seeing your reply.
You need to use ‘ones(1,length(hxt))*ypos’ to make the x and y vectors equal for the ‘text’ statement, but you’ve already figured that out.

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

その他の回答 (1 件)

dpb
dpb 2014 年 7 月 13 日
編集済み: dpb 2014 年 7 月 13 日

2 投票

For some unfathomable reason, TMW has not implemented the TeX or LaTeX interpreter for axis labels so you'll have no joy that route.
set(gca,'xticklabel',[]) % hide the existing labels
then use
xt=get(gca,'xtick').';
text(xt,-0.2*ones(size(xt)),num2str(xt-1,'I_%d'), ...
'horizontal','center')
(ADDENDUM--incorporate the horizontal alignment to center)
Salt to suit...

1 件のコメント

Aravin
Aravin 2014 年 7 月 14 日
Thank you.

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

カテゴリ

質問済み:

2014 年 7 月 13 日

コメント済み:

2014 年 7 月 14 日

Community Treasure Hunt

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

Start Hunting!

Translated by