formatting axes for a plot

Hello,
Why whenever I do this to format the x-axis to be between 0-6 and then type (x10^4) it does not show the x-ticks on the x-axis:
xVals = 0:.6:6;
set(gca,'xtick',xVals);
expVal = 4; %exponent you want
set(gca,'XTickLabel',sprintf('%2.1f|',xVals));%10^expVal));
pos = get(gca,'Position');
offset = 0.00; %how far to the right you want the exponent
annotation('textbox',[pos(1)+ pos(3)+offset, pos(2), 0.2, 0.2],...
'String',['$\times 10^' num2str(expVal) '$'],...
'Interpreter','latex',...
'VerticalAlignment','bottom',...
'EdgeColor','none')

 Respuesta aceptada

José-Luis
José-Luis el 1 de En. de 2013

0 votos

If all you want to do is to add the annotation in your plot, you don't need to add the 'XTicks'.
You could just add this section to your original code:
pos = get(gca,'Position');
offset = 0.00; %how far to the right you want the exponent
annotation('textbox',[pos(1)+ pos(3)+offset, pos(2), 0.2, 0.2],...
'String',['$\times 10^' num2str(expVal) '$'],...
'Interpreter','latex',...
'VerticalAlignment','bottom',...
'EdgeColor','none')

5 comentarios

Sam Alex
Sam Alex el 1 de En. de 2013
The annotation and x-labels where it is custom: for example my data does from 0-60000 and I want the step to be 6000...I am doing it in the code above as you see but it is not working and I am wondering why!
José-Luis
José-Luis el 2 de En. de 2013
I don't understand. How do you want the labels to appear?
Sam Alex
Sam Alex el 2 de En. de 2013
I want to force the plot have numbers on the x-axis like this: 0, 0.6, 1.2, 1.8, 2.4, 3.0, 3.6, 4.2, 4.8, 5.4
José-Luis
José-Luis el 2 de En. de 2013
x = 0:6000:60000;
y = randn(numel(x),1);
plot(x,y,'b-o')
xVals = x;
set(gca,'xtick',xVals);
expVal = 4; %exponent you want
set(gca,'XTickLabel',sprintf('%2.1f|',xVals./(10^expVal)));
pos = get(gca,'Position');
offset = 0.00; %how far to the right you want the exponent
annotation('textbox',[pos(1)+ pos(3)+offset, pos(2), 0.2, 0.2],...
'String',['$\times 10^' num2str(expVal) '$'],...
'Interpreter','latex',...
'VerticalAlignment','bottom',...
'EdgeColor','none')
Sam Alex
Sam Alex el 2 de En. de 2013
Thank you

Iniciar sesión para comentar.

Más respuestas (1)

Azzi Abdelmalek
Azzi Abdelmalek el 1 de En. de 2013

1 voto

Add to your code
set(gca,'xlim',[0 6])

4 comentarios

Sam Alex
Sam Alex el 1 de En. de 2013
It did not make a difference!
Azzi Abdelmalek
Azzi Abdelmalek el 1 de En. de 2013
Editada: Azzi Abdelmalek el 1 de En. de 2013
There is a difference, in this case, x-ticks are visibles
close
xVals = 0:.6:6;
set(gca,'xtick',xVals);
expVal = 4; %exponent you want
set(gca,'XTickLabel',sprintf('%2.1f|',xVals));%10^expVal));
pos = get(gca,'Position');
offset = 0.00; %how far to the right you want the exponent
annotation('textbox',[pos(1)+ pos(3)+offset, pos(2), 0.2, 0.2],...
'String',['$\times 10^' num2str(expVal) '$'],...
'Interpreter','latex',...
'VerticalAlignment','bottom',...
'EdgeColor','none')
set(gca,'xlim',[0 6])
Sam Alex
Sam Alex el 1 de En. de 2013
Something happens when I add this to my code, it removes all markers and the look of the original plot
Azzi Abdelmalek
Azzi Abdelmalek el 1 de En. de 2013
Post the code which is making a problem

Iniciar sesión para comentar.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by