How to subscript in figures

8 visualizaciones (últimos 30 días)
Aravin
Aravin el 13 de Jul. de 2014
Comentada: Star Strider el 14 de Jul. de 2014
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.

Respuesta aceptada

Star Strider
Star Strider el 13 de Jul. de 2014
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 comentarios
Aravin
Aravin el 14 de Jul. de 2014
I have Figured it out. Thank you.
Star Strider
Star Strider el 14 de Jul. de 2014
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.

Iniciar sesión para comentar.

Más respuestas (1)

dpb
dpb el 13 de Jul. de 2014
Editada: dpb el 13 de Jul. de 2014
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...

Community Treasure Hunt

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

Start Hunting!

Translated by